From 628e5cd9f26bc7f7924b4db0af02fadd47bbd815 Mon Sep 17 00:00:00 2001 From: Zhihong Yu Date: Thu, 16 Feb 2012 13:56:40 +0000 Subject: [PATCH] HBASE-5411 Add more metrics for ThriftMetrics (Scott Chen) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1244977 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/thrift/ThriftMetrics.java | 12 ++++++++++++ .../hadoop/hbase/thrift/ThriftServerRunner.java | 16 +++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/hadoop/hbase/thrift/ThriftMetrics.java b/src/main/java/org/apache/hadoop/hbase/thrift/ThriftMetrics.java index d2b8e589622..d24587f8a5c 100644 --- a/src/main/java/org/apache/hadoop/hbase/thrift/ThriftMetrics.java +++ b/src/main/java/org/apache/hadoop/hbase/thrift/ThriftMetrics.java @@ -54,6 +54,10 @@ public class ThriftMetrics implements Updater { 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 Updater { 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) { diff --git a/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java b/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java index a15f4c8db67..f5c62621352 100644 --- a/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java +++ b/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java @@ -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.generated.AlreadyExists; 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 implements Runnable { 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 implements Runnable { // nextScannerId and scannerMap are used to manage scanner state protected int nextScannerId = 0; protected HashMap scannerMap = null; + private ThriftMetrics metrics = null; private static ThreadLocal> threadLocalTables = new ThreadLocal>() { @@ -773,6 +773,9 @@ public class ThriftServerRunner implements Runnable { try { List gets = new ArrayList(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 implements Runnable { 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 implements Runnable { throw new IOError(e.getMessage()); } } + + private void initMetrics(ThriftMetrics metrics) { + this.metrics = metrics; + } } /** * Adds all the attributes into the Operation object