HBASE-6602 Region Server Dynamic Metrics can cause high cpu usage.

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1374397 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2012-08-17 19:02:13 +00:00
parent a20fb9700f
commit 283155ef05
1 changed files with 19 additions and 17 deletions

View File

@ -64,6 +64,7 @@ public class RegionServerDynamicMetrics implements Updater {
LogFactory.getLog(RegionServerDynamicStatistics.class);
private boolean reflectionInitialized = false;
private boolean needsUpdateMessage = false;
private Field recordMetricMapField;
private Field registryMetricMapField;
@ -102,14 +103,7 @@ public class RegionServerDynamicMetrics implements Updater {
MetricsLongValue m = (MetricsLongValue)registry.get(name);
if (m == null) {
m = new MetricsLongValue(name, this.registry);
try {
if (updateMbeanInfoIfMetricsListChanged != null) {
updateMbeanInfoIfMetricsListChanged.invoke(this.rsDynamicStatistics,
new Object[]{});
}
} catch (Exception e) {
LOG.error(e);
}
this.needsUpdateMessage = true;
}
m.set(amt);
}
@ -121,14 +115,7 @@ public class RegionServerDynamicMetrics implements Updater {
MetricsTimeVaryingRate m = (MetricsTimeVaryingRate)registry.get(name);
if (m == null) {
m = new MetricsTimeVaryingRate(name, this.registry);
try {
if (updateMbeanInfoIfMetricsListChanged != null) {
updateMbeanInfoIfMetricsListChanged.invoke(this.rsDynamicStatistics,
new Object[]{});
}
} catch (Exception e) {
LOG.error(e);
}
this.needsUpdateMessage = true;
}
if (numOps > 0) {
m.inc(numOps, amt);
@ -141,7 +128,7 @@ public class RegionServerDynamicMetrics implements Updater {
*/
@SuppressWarnings("rawtypes")
public void clear() {
this.needsUpdateMessage = true;
// If this is the first clear use reflection to get the two maps that hold copies of our
// metrics on the hadoop metrics side. We have to use reflection because there is not
// remove metrics on the hadoop side. If we can't get them then clearing old metrics
@ -212,6 +199,21 @@ public class RegionServerDynamicMetrics implements Updater {
value.getSecond().getAndSet(0));
}
// If there are new metrics sending this message to jmx tells it to update everything.
// This is not ideal we should just move to metrics2 that has full support for dynamic metrics.
if (needsUpdateMessage) {
try {
if (updateMbeanInfoIfMetricsListChanged != null) {
updateMbeanInfoIfMetricsListChanged.invoke(this.rsDynamicStatistics,
new Object[]{});
}
} catch (Exception e) {
LOG.error(e);
}
needsUpdateMessage = false;
}
synchronized (registry) {
// Iterate through the registry to propagate the different rpc metrics.
for (String metricName : registry.getKeyList() ) {