Author: tedyu
Date: Thu Feb 16 13:56:40 2012
New Revision: 1244977

URL: http://svn.apache.org/viewvc?rev=1244977&view=rev
Log:
HBASE-5411 Add more metrics for ThriftMetrics (Scott Chen)

Modified:
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftMetrics.java
    
hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java

Modified: 
hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftMetrics.java
URL: 
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftMetrics.java?rev=1244977&r1=1244976&r2=1244977&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftMetrics.java 
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftMetrics.java 
Thu Feb 16 13:56:40 2012
@@ -54,6 +54,10 @@ public class ThriftMetrics implements Up
 
   private final MetricsIntValue callQueueLen =
       new MetricsIntValue("callQueueLen", registry);
+  private final MetricsTimeVaryingRate numRowKeysInBatchGet =
+      new MetricsTimeVaryingRate("numRowKeysInBatchGet", registry);
+  private final MetricsTimeVaryingRate numRowKeysInBatchMutate =
+      new MetricsTimeVaryingRate("numRowKeysInBatchMutate", registry);
   private final MetricsTimeVaryingRate timeInQueue =
       new MetricsTimeVaryingRate("timeInQueue", registry);
   private MetricsTimeVaryingRate thriftCall =
@@ -84,6 +88,14 @@ public class ThriftMetrics implements Up
     callQueueLen.set(len);
   }
 
+  public void incNumRowKeysInBatchGet(int diff) {
+    numRowKeysInBatchGet.inc(diff);
+  }
+
+  public void incNumRowKeysInBatchMutate(int diff) {
+    numRowKeysInBatchMutate.inc(diff);
+  }
+
   public void incMethodTime(String name, int time) {
     MetricsTimeVaryingRate methodTimeMetrc = getMethodTimeMetrics(name);
     if (methodTimeMetrc == null) {

Modified: 
hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java
URL: 
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java?rev=1244977&r1=1244976&r2=1244977&view=diff
==============================================================================
--- 
hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java
 (original)
+++ 
hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java
 Thu Feb 16 13:56:40 2012
@@ -31,7 +31,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
-import java.util.Map.Entry;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.LinkedBlockingQueue;
@@ -69,8 +68,8 @@ import org.apache.hadoop.hbase.thrift.ge
 import org.apache.hadoop.hbase.thrift.generated.BatchMutation;
 import org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor;
 import org.apache.hadoop.hbase.thrift.generated.Hbase;
-import org.apache.hadoop.hbase.thrift.generated.IllegalArgument;
 import org.apache.hadoop.hbase.thrift.generated.IOError;
+import org.apache.hadoop.hbase.thrift.generated.IllegalArgument;
 import org.apache.hadoop.hbase.thrift.generated.Mutation;
 import org.apache.hadoop.hbase.thrift.generated.TCell;
 import org.apache.hadoop.hbase.thrift.generated.TRegionInfo;
@@ -227,8 +226,8 @@ public class ThriftServerRunner implemen
     this.conf = HBaseConfiguration.create(conf);
     this.listenPort = conf.getInt(PORT_CONF_KEY, DEFAULT_LISTEN_PORT);
     this.metrics = new ThriftMetrics(listenPort, conf, Hbase.Iface.class);
+    handler.initMetrics(metrics);
     this.handler = HbaseHandlerMetricsProxy.newInstance(handler, metrics, 
conf);
-
   }
 
   /*
@@ -395,6 +394,7 @@ public class ThriftServerRunner implemen
     // nextScannerId and scannerMap are used to manage scanner state
     protected int nextScannerId = 0;
     protected HashMap<Integer, ResultScanner> scannerMap = null;
+    private ThriftMetrics metrics = null;
 
     private static ThreadLocal<Map<String, HTable>> threadLocalTables =
         new ThreadLocal<Map<String, HTable>>() {
@@ -773,6 +773,9 @@ public class ThriftServerRunner implemen
       try {
         List<Get> gets = new ArrayList<Get>(rows.size());
         HTable table = getTable(tableName);
+        if (metrics != null) {
+          metrics.incNumRowKeysInBatchGet(rows.size());
+        }
         for (ByteBuffer row : rows) {
           Get get = new Get(getBytes(row));
           addAttributes(get, attributes);
@@ -908,6 +911,9 @@ public class ThriftServerRunner implemen
 
         Delete delete = new Delete(getBytes(row));
         addAttributes(delete, attributes);
+        if (metrics != null) {
+          metrics.incNumRowKeysInBatchMutate(mutations.size());
+        }
 
         // I apologize for all this mess :)
         for (Mutation m : mutations) {
@@ -1315,6 +1321,10 @@ public class ThriftServerRunner implemen
         throw new IOError(e.getMessage());
       }
     }
+
+    private void initMetrics(ThriftMetrics metrics) {
+      this.metrics = metrics;
+    }
   }
   /**
    * Adds all the attributes into the Operation object


Reply via email to