hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1377107 - in /hbase/branches/0.94/src: main/java/org/apache/hadoop/hbase/metrics/ main/java/org/apache/hadoop/hbase/metrics/histogram/ test/java/org/apache/hadoop/hbase/coprocessor/ test/java/org/apache/hadoop/hbase/metrics/
Date Fri, 24 Aug 2012 20:53:37 GMT
Author: stack
Date: Fri Aug 24 20:53:37 2012
New Revision: 1377107

URL: http://svn.apache.org/viewvc?rev=1377107&view=rev
Log:
HBASE-6211 Put latencies in jmx

Modified:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/metrics/MetricsMBeanBase.java
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/metrics/histogram/MetricsHistogram.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/metrics/TestMetricsMBeanBase.java

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/metrics/MetricsMBeanBase.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/metrics/MetricsMBeanBase.java?rev=1377107&r1=1377106&r2=1377107&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/metrics/MetricsMBeanBase.java
(original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/metrics/MetricsMBeanBase.java
Fri Aug 24 20:53:37 2012
@@ -29,7 +29,9 @@ import javax.management.MBeanAttributeIn
 import javax.management.MBeanException;
 import javax.management.MBeanInfo;
 import javax.management.ReflectionException;
+import org.apache.hadoop.hbase.metrics.histogram.MetricsHistogram;
 
+import com.yammer.metrics.stats.Snapshot;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.metrics.util.MetricsBase;
@@ -104,6 +106,52 @@ public class MetricsMBeanBase extends Me
             "java.lang.String", metric.getDescription(), true, false, false) );
         extendedAttributes.put(metric.getName(), metric);
         LOG.info("MetricsString added: " + metric.getName());
+      } else if (metric instanceof MetricsHistogram) {
+
+        String metricName = metric.getName() + MetricsHistogram.NUM_OPS_METRIC_NAME;
+        attributes.add(new MBeanAttributeInfo(metricName,
+            "java.lang.Long", metric.getDescription(), true, false, false));
+        extendedAttributes.put(metricName, metric);
+
+        metricName = metric.getName() + MetricsHistogram.MIN_METRIC_NAME;
+        attributes.add(new MBeanAttributeInfo(metricName,
+            "java.lang.Long", metric.getDescription(), true, false, false));
+        extendedAttributes.put(metricName, metric);
+
+        metricName = metric.getName() + MetricsHistogram.MAX_METRIC_NAME;
+        attributes.add(new MBeanAttributeInfo(metricName,
+            "java.lang.Long", metric.getDescription(), true, false, false));
+        extendedAttributes.put(metricName, metric);
+
+        metricName = metric.getName() + MetricsHistogram.MEAN_METRIC_NAME;
+        attributes.add(new MBeanAttributeInfo(metricName,
+            "java.lang.Float", metric.getDescription(), true, false, false));
+        extendedAttributes.put(metricName, metric);
+
+        metricName = metric.getName() + MetricsHistogram.STD_DEV_METRIC_NAME;
+        attributes.add(new MBeanAttributeInfo(metricName,
+            "java.lang.Float", metric.getDescription(), true, false, false));
+        extendedAttributes.put(metricName, metric);
+
+        metricName = metric.getName() + MetricsHistogram.MEDIAN_METRIC_NAME;
+        attributes.add(new MBeanAttributeInfo(metricName,
+            "java.lang.Float", metric.getDescription(), true, false, false));
+        extendedAttributes.put(metricName, metric);
+
+        metricName = metric.getName() + MetricsHistogram.SEVENTY_FIFTH_PERCENTILE_METRIC_NAME;
+        attributes.add(new MBeanAttributeInfo(metricName,
+            "java.lang.Float", metric.getDescription(), true, false, false));
+        extendedAttributes.put(metricName, metric);
+
+        metricName = metric.getName() + MetricsHistogram.NINETY_FIFTH_PERCENTILE_METRIC_NAME;
+        attributes.add(new MBeanAttributeInfo(metricName,
+            "java.lang.Float", metric.getDescription(), true, false, false));
+        extendedAttributes.put(metricName, metric);
+
+        metricName = metric.getName() + MetricsHistogram.NINETY_NINETH_PERCENTILE_METRIC_NAME;
+        attributes.add(new MBeanAttributeInfo(metricName,
+            "java.lang.Float", metric.getDescription(), true, false, false));
+        extendedAttributes.put(metricName, metric);
       }
       // else, its probably a hadoop metric already registered. Skip it.
     }
@@ -148,6 +196,32 @@ public class MetricsMBeanBase extends Me
           return ((MetricsRate) metric).getPreviousIntervalValue();
         } else if (metric instanceof MetricsString) {
           return ((MetricsString)metric).getValue();
+        } else if (metric instanceof MetricsHistogram)  {
+          MetricsHistogram hist = (MetricsHistogram) metric;
+          if (name.endsWith(MetricsHistogram.NUM_OPS_METRIC_NAME)) {
+            return hist.getCount();
+          } else if (name.endsWith(MetricsHistogram.MIN_METRIC_NAME)) {
+            return hist.getMin();
+          } else if (name.endsWith(MetricsHistogram.MAX_METRIC_NAME)) {
+            return hist.getMax();
+          } else if (name.endsWith(MetricsHistogram.MEAN_METRIC_NAME)) {
+            return (float) hist.getMean();
+          } else if (name.endsWith(MetricsHistogram.STD_DEV_METRIC_NAME)) {
+            return (float) hist.getStdDev();
+          } else if (name.endsWith(MetricsHistogram.MEDIAN_METRIC_NAME)) {
+            Snapshot s = hist.getSnapshot();
+            return (float) s.getMedian();
+          } else if (name.endsWith(MetricsHistogram.SEVENTY_FIFTH_PERCENTILE_METRIC_NAME))
{
+            Snapshot s = hist.getSnapshot();
+            return (float) s.get75thPercentile();
+          } else if (name.endsWith(MetricsHistogram.NINETY_FIFTH_PERCENTILE_METRIC_NAME))
{
+            Snapshot s = hist.getSnapshot();
+            return (float) s.get95thPercentile();
+          } else if (name.endsWith(MetricsHistogram.NINETY_NINETH_PERCENTILE_METRIC_NAME))
{
+            Snapshot s = hist.getSnapshot();
+            return (float) s.get99thPercentile();
+          }
+
         } else {
           LOG.warn( String.format("unknown metrics type %s for attribute %s",
                         metric.getClass().getName(), name) );

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/metrics/histogram/MetricsHistogram.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/metrics/histogram/MetricsHistogram.java?rev=1377107&r1=1377106&r2=1377107&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/metrics/histogram/MetricsHistogram.java
(original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/metrics/histogram/MetricsHistogram.java
Fri Aug 24 20:53:37 2012
@@ -39,6 +39,15 @@ public class MetricsHistogram extends Me
   // the bias towards sampling from more recent data. 
   // Per Cormode et al. an alpha of 0.015 strongly biases to the last 5 minutes
   private static final double DEFAULT_ALPHA = 0.015;
+  public static final String NUM_OPS_METRIC_NAME = "_num_ops";
+  public static final String MIN_METRIC_NAME = "_min";
+  public static final String MAX_METRIC_NAME = "_max";
+  public static final String MEAN_METRIC_NAME = "_mean";
+  public static final String STD_DEV_METRIC_NAME = "_std_dev";
+  public static final String MEDIAN_METRIC_NAME = "_median";
+  public static final String SEVENTY_FIFTH_PERCENTILE_METRIC_NAME = "_75th_percentile";
+  public static final String NINETY_FIFTH_PERCENTILE_METRIC_NAME = "_95th_percentile";
+  public static final String NINETY_NINETH_PERCENTILE_METRIC_NAME = "_99th_percentile";
 
   /**
    * Constructor to create a new histogram metric
@@ -212,19 +221,19 @@ public class MetricsHistogram extends Me
   @Override
   public void pushMetric(MetricsRecord mr) {
     final Snapshot s = this.getSnapshot();
-    mr.setMetric(getName() + "_num_ops", this.getCount());
-    mr.setMetric(getName() + "_min", this.getMin());
-    mr.setMetric(getName() + "_max", this.getMax());
-    
-    mr.setMetric(getName() + "_mean", (float) this.getMean());
-    mr.setMetric(getName() + "_std_dev", (float) this.getStdDev());
-    
-    mr.setMetric(getName() + "_median", (float) s.getMedian());
-    mr.setMetric(getName() + "_75th_percentile", 
+    mr.setMetric(getName() + NUM_OPS_METRIC_NAME, this.getCount());
+    mr.setMetric(getName() + MIN_METRIC_NAME, this.getMin());
+    mr.setMetric(getName() + MAX_METRIC_NAME, this.getMax());
+
+    mr.setMetric(getName() + MEAN_METRIC_NAME, (float) this.getMean());
+    mr.setMetric(getName() + STD_DEV_METRIC_NAME, (float) this.getStdDev());
+
+    mr.setMetric(getName() + MEDIAN_METRIC_NAME, (float) s.getMedian());
+    mr.setMetric(getName() + SEVENTY_FIFTH_PERCENTILE_METRIC_NAME,
         (float) s.get75thPercentile());
-    mr.setMetric(getName() + "_95th_percentile", 
+    mr.setMetric(getName() + NINETY_FIFTH_PERCENTILE_METRIC_NAME,
         (float) s.get95thPercentile());
-    mr.setMetric(getName() + "_99th_percentile", 
+    mr.setMetric(getName() + NINETY_NINETH_PERCENTILE_METRIC_NAME,
         (float) s.get99thPercentile());
   }
 }

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java?rev=1377107&r1=1377106&r2=1377107&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java
(original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java
Fri Aug 24 20:53:37 2012
@@ -31,6 +31,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.NavigableMap;
 
+import junit.framework.Assert;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
@@ -684,6 +686,8 @@ public class TestMasterObserver {
     // move half the open regions from RS 0 to RS 1
     HRegionServer rs = cluster.getRegionServer(0);
     byte[] destRS = Bytes.toBytes(cluster.getRegionServer(1).getServerName().toString());
+    //Make sure no regions are in transition now
+    waitForRITtoBeZero(master);
     List<HRegionInfo> openRegions = rs.getOnlineRegions();
     int moveCnt = openRegions.size()/2;
     for (int i=0; i<moveCnt; i++) {
@@ -692,7 +696,16 @@ public class TestMasterObserver {
         master.move(openRegions.get(i).getEncodedNameAsBytes(), destRS);
       }
     }
+    //Make sure no regions are in transition now
+    waitForRITtoBeZero(master);
+    // now trigger a balance
+    master.balanceSwitch(true);
+    boolean balanceRun = master.balance();
+    assertTrue("Coprocessor should be called on region rebalancing",
+        cp.wasBalanceCalled());
+  }
 
+  private void waitForRITtoBeZero(HMaster master) throws IOException {
     // wait for assignments to finish
     AssignmentManager mgr = master.getAssignmentManager();
     Collection<AssignmentManager.RegionState> transRegions =
@@ -700,13 +713,6 @@ public class TestMasterObserver {
     for (AssignmentManager.RegionState state : transRegions) {
       mgr.waitOnRegionToClearRegionsInTransition(state.getRegion());
     }
-
-    // now trigger a balance
-    master.balanceSwitch(true);
-    boolean balanceRun = master.balance();
-    assertTrue("Coprocessor should be called on region rebalancing",
-        cp.wasBalanceCalled());
-    table.close();
   }
 
   @org.junit.Rule

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/metrics/TestMetricsMBeanBase.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/metrics/TestMetricsMBeanBase.java?rev=1377107&r1=1377106&r2=1377107&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/metrics/TestMetricsMBeanBase.java
(original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/metrics/TestMetricsMBeanBase.java
Fri Aug 24 20:53:37 2012
@@ -24,8 +24,13 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.management.AttributeNotFoundException;
 import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanException;
 import javax.management.MBeanInfo;
+import javax.management.ReflectionException;
+import org.apache.hadoop.hbase.metrics.histogram.MetricsHistogram;
+import com.yammer.metrics.stats.Snapshot;
 
 import org.apache.hadoop.hbase.MediumTests;
 import org.apache.hadoop.metrics.MetricsContext;
@@ -35,6 +40,9 @@ import org.apache.hadoop.metrics.util.Me
 import org.apache.hadoop.metrics.util.MetricsRegistry;
 import org.apache.hadoop.metrics.util.MetricsTimeVaryingRate;
 
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 import junit.framework.TestCase;
 import org.junit.experimental.categories.Category;
 
@@ -114,6 +122,52 @@ public class TestMetricsMBeanBase extend
         "varyRateNumOps", "java.lang.Integer", "test");
   }
 
+  public void testMetricsMBeanBaseHistogram()
+      throws ReflectionException, AttributeNotFoundException, MBeanException {
+    MetricsRegistry mr = new MetricsRegistry();
+    MetricsHistogram histo = mock(MetricsHistogram.class);
+    Snapshot snap = mock(Snapshot.class);
+
+    //Set up the mocks
+    String histoName = "MockHisto";
+    when(histo.getName()).thenReturn(histoName);
+    when(histo.getCount()).thenReturn(20l);
+    when(histo.getMin()).thenReturn(1l);
+    when(histo.getMax()).thenReturn(999l);
+    when(histo.getMean()).thenReturn(500.2);
+    when(histo.getStdDev()).thenReturn(1.2);
+    when(histo.getSnapshot()).thenReturn(snap);
+
+    when(snap.getMedian()).thenReturn(490.0);
+    when(snap.get75thPercentile()).thenReturn(550.0);
+    when(snap.get95thPercentile()).thenReturn(900.0);
+    when(snap.get99thPercentile()).thenReturn(990.0);
+
+    mr.add("myTestHisto", histo);
+
+    MetricsMBeanBase mBeanBase = new MetricsMBeanBase(mr, "test");
+
+    assertEquals(new Long(20), mBeanBase
+        .getAttribute(histoName + MetricsHistogram.NUM_OPS_METRIC_NAME));
+    assertEquals(new Long(1), mBeanBase
+        .getAttribute(histoName + MetricsHistogram.MIN_METRIC_NAME));
+    assertEquals(new Long(999), mBeanBase
+        .getAttribute(histoName + MetricsHistogram.MAX_METRIC_NAME));
+    assertEquals(new Float(500.2), mBeanBase
+        .getAttribute(histoName + MetricsHistogram.MEAN_METRIC_NAME));
+    assertEquals(new Float(1.2), mBeanBase
+        .getAttribute(histoName + MetricsHistogram.STD_DEV_METRIC_NAME));
+
+    assertEquals(new Float(490.0), mBeanBase
+        .getAttribute(histoName + MetricsHistogram.MEDIAN_METRIC_NAME));
+    assertEquals(new Float(550.0), mBeanBase
+        .getAttribute(histoName + MetricsHistogram.SEVENTY_FIFTH_PERCENTILE_METRIC_NAME));
+    assertEquals(new Float(900.0), mBeanBase
+        .getAttribute(histoName + MetricsHistogram.NINETY_FIFTH_PERCENTILE_METRIC_NAME));
+    assertEquals(new Float(990.0), mBeanBase
+        .getAttribute(histoName + MetricsHistogram.NINETY_NINETH_PERCENTILE_METRIC_NAME));
+  }
+
   protected void assertAttribute(MBeanAttributeInfo attr, String name,
       String type, String description) {
 



Mime
View raw message