Author: mbautin Date: Fri Feb 17 01:56:16 2012 New Revision: 1245289 URL: http://svn.apache.org/viewvc?rev=1245289&view=rev Log: [HBASE-5411]More Hbase thrift server metrics
Summary: 1. connections to the thrift servers 2. # rowkeys in batch puts 3. # of keys in batch gets Test Plan: Unit tests Reviewers: kannan, dhruba Reviewed By: dhruba CC: hbase@lists, davejwatson Differential Revision: https://phabricator.fb.com/D409330 Task ID: 811151 Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/thrift/HBaseThreadPoolServer.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/thrift/ThriftMetrics.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/thrift/HBaseThreadPoolServer.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/thrift/HBaseThreadPoolServer.java?rev=1245289&r1=1245288&r2=1245289&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/thrift/HBaseThreadPoolServer.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/thrift/HBaseThreadPoolServer.java Fri Feb 17 01:56:16 2012 @@ -107,6 +107,8 @@ public class HBaseThreadPoolServer exten private final int KEEP_ALIVE_TIME_SEC = 60; + private final ThriftMetrics metrics; + public HBaseThreadPoolServer(TProcessor processor, TServerTransport serverTransport, TTransportFactory transportFactory, @@ -116,6 +118,8 @@ public class HBaseThreadPoolServer exten super(new TProcessorFactory(processor), serverTransport, transportFactory, transportFactory, protocolFactory, protocolFactory); + this.metrics = metrics; + BlockingQueue<Runnable> executorQueue; if (options.maxQueuedRequests > 0) { executorQueue = new CallQueue( @@ -155,6 +159,7 @@ public class HBaseThreadPoolServer exten TTransport client = null; try { client = serverTransport_.accept(); + metrics.incNumConnections(1); } catch (TTransportException ttx) { if (!stopped) { LOG.warn("Transport error when accepting message", ttx); @@ -176,6 +181,7 @@ public class HBaseThreadPoolServer exten } else { LOG.warn(QUEUE_FULL_MSG, rex); } + metrics.incNumConnections(-1); client.close(); } } @@ -277,6 +283,7 @@ public class HBaseThreadPoolServer exten if (outputTransport != null) { outputTransport.close(); } + metrics.incNumConnections(-1); } } } Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/thrift/ThriftMetrics.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/thrift/ThriftMetrics.java?rev=1245289&r1=1245288&r2=1245289&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/thrift/ThriftMetrics.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/thrift/ThriftMetrics.java Fri Feb 17 01:56:16 2012 @@ -33,7 +33,6 @@ import org.apache.hadoop.metrics.util.Me import org.apache.hadoop.metrics.util.MetricsIntValue; import org.apache.hadoop.metrics.util.MetricsRegistry; import org.apache.hadoop.metrics.util.MetricsTimeVaryingInt; -import org.apache.hadoop.metrics.util.MetricsTimeVaryingLong; import org.apache.hadoop.metrics.util.MetricsTimeVaryingRate; /** @@ -54,6 +53,12 @@ public class ThriftMetrics implements Up private final MetricsIntValue callQueueLen = new MetricsIntValue("callQueueLen", registry); + private final MetricsTimeVaryingInt numConnections = + new MetricsTimeVaryingInt("numConnections", registry); + private final MetricsTimeVaryingRate numBatchGetRowKeys = + new MetricsTimeVaryingRate("numBatchGetRowKeys", registry); + private final MetricsTimeVaryingRate numBatchMutateRowKeys = + new MetricsTimeVaryingRate("numBatchMutateRowKeys", registry); private final MetricsTimeVaryingRate timeInQueue = new MetricsTimeVaryingRate("timeInQueue", registry); private MetricsTimeVaryingRate thriftCall = @@ -84,6 +89,18 @@ public class ThriftMetrics implements Up callQueueLen.set(len); } + public void incNumConnections(int diff) { + numConnections.inc(diff); + } + + public void incNumBatchGetRowKeys(int diff) { + numBatchGetRowKeys.inc(diff); + } + + public void incNumBatchMutateRowKeys(int diff) { + numBatchMutateRowKeys.inc(diff); + } + public void incMethodTime(String name, int time) { MetricsTimeVaryingRate methodTimeMetrc = getMethodTimeMetrics(name); if (methodTimeMetrc == null) { Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java?rev=1245289&r1=1245288&r2=1245289&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java Fri Feb 17 01:56:16 2012 @@ -108,6 +108,8 @@ public class ThriftServer { protected int nextScannerId = 0; protected HashMap<Integer, ResultScanner> scannerMap = null; + final private ThriftMetrics metrics; + private static ThreadLocal<Map<String, HTable>> threadLocalTables = new ThreadLocal<Map<String, HTable>>() { @Override protected Map<String, HTable> initialValue() { @@ -187,18 +189,26 @@ public class ThriftServer { } /** Constructs a handler with configuration based on the given one. */ - protected HBaseHandler(HBaseConfiguration conf) throws IOException { - this(HBaseConfiguration.create(conf)); + protected HBaseHandler( + HBaseConfiguration conf, ThriftMetrics metrics) throws IOException { + this(HBaseConfiguration.create(conf), metrics); LOG.debug("Creating HBaseHandler with ZK client port " + conf.get(HConstants.ZOOKEEPER_CLIENT_PORT)); } - protected HBaseHandler(final Configuration c) throws IOException { + protected HBaseHandler( + final Configuration c, ThriftMetrics metrics) throws IOException { + this.metrics = metrics; this.conf = c; admin = new HBaseAdmin(conf); scannerMap = new HashMap<Integer, ResultScanner>(); } + /** Create a handler without metrics. Used by unit test only */ + HBaseHandler(final Configuration c) throws IOException { + this(c, null); + } + public void enableTable(final byte[] tableName) throws IOError { try{ admin.enableTable(tableName); @@ -469,6 +479,10 @@ public class ThriftServer { try { List<Get> gets = new ArrayList<Get>(rows.size()); HTable table = getTable(tableName); + if (metrics != null) { + metrics.incNumBatchGetRowKeys(rows.size()); + } + // For now, don't support ragged gets, with different columns per row // Probably pretty sensible indefinitely anyways. for (byte[] row : rows) { @@ -611,6 +625,9 @@ public class ThriftServer { throws IOError, IllegalArgument, TException { List<Put> puts = new ArrayList<Put>(); List<Delete> deletes = new ArrayList<Delete>(); + if (metrics != null) { + metrics.incNumBatchMutateRowKeys(rowBatches.size()); + } for (BatchMutation batch : rowBatches) { byte[] row = batch.row; @@ -1135,7 +1152,7 @@ public class ThriftServer { } ThriftMetrics metrics = new ThriftMetrics(listenPort, conf); - Hbase.Iface handler = new HBaseHandler(conf); + Hbase.Iface handler = new HBaseHandler(conf, metrics); handler = HbaseHandlerMetricsProxy.newInstance(handler, metrics, conf); Hbase.Processor processor = new Hbase.Processor(handler);
