HBASE-4304 requestsPerSecond counter stuck at 0

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1190167 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2011-10-28 06:09:32 +00:00
parent 0e83d7445d
commit 91090148f7
5 changed files with 12 additions and 6 deletions

View File

@ -415,6 +415,7 @@ Release 0.92.0 - Unreleased
HBASE-4300 Start of new-version master fails if old master's znode is
hanging around
HBASE-4679 Thrift null mutation error
HBASE-4304 requestsPerSecond counter stuck at 0 (Li Pi)
TESTS
HBASE-4450 test for number of blocks read: to serve as baseline for expected

View File

@ -56,10 +56,14 @@ public class MetricsRate extends MetricsBase {
value++;
}
private synchronized void intervalHeartBeat() {
public synchronized void intervalHeartBeat() {
long now = System.currentTimeMillis();
long diff = (now-ts) / 1000;
if (diff == 0) diff = 1; // sigh this is crap.
if (diff < 1){
// To make sure our averages aren't skewed by fast repeated calls,
// we simply ignore fast repeated calls.
return;
}
this.prevRate = (float)value / diff;
this.value = 0;
this.ts = now;

View File

@ -1018,7 +1018,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
/**
* @param encodedRegionName
* @return An instance of RegionLoad.
* @throws IOException
*/
public HServerLoad.RegionLoad createRegionLoad(final String encodedRegionName) {
HRegion r = null;
@ -1275,6 +1274,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
protected void metrics() {
this.metrics.regions.set(this.onlineRegions.size());
this.metrics.incrementRequests(this.requestCount.get());
this.metrics.requests.intervalHeartBeat();
// Is this too expensive every three seconds getting a lock on onlineRegions
// and then per store carried? Can I make metrics be sloppier and avoid
// the synchronizations?

View File

@ -116,7 +116,7 @@ public class RegionServerMetrics implements Updater {
/*
* Count of requests to the regionservers since last call to metrics update
*/
private final MetricsRate requests = new MetricsRate("requests", registry);
public final MetricsRate requests = new MetricsRate("requests", registry);
/**
* Count of stores open on the regionserver.

View File

@ -70,6 +70,7 @@ public class TestMetricsMBeanBase extends TestCase {
public void testGetAttribute() throws Exception {
this.metricsRate.inc(2);
Thread.sleep(1000);
this.metricsRate.pushMetric(this.metricsRecord);
this.intValue.set(5);
this.intValue.pushMetric(this.metricsRecord);
@ -78,7 +79,7 @@ public class TestMetricsMBeanBase extends TestCase {
this.varyRate.pushMetric(this.metricsRecord);
assertEquals( 2.0, (Float)this.stats.getAttribute("metricsRate"), 0.001 );
assertEquals( 2.0, (Float)this.stats.getAttribute("metricsRate"), 0.005 );
assertEquals( 5, this.stats.getAttribute("intValue") );
assertEquals( 10L, this.stats.getAttribute("varyRateMinTime") );
assertEquals( 50L, this.stats.getAttribute("varyRateMaxTime") );