HBASE-18469 Correct RegionServer metric of totalRequestCount

This commit is contained in:
Yu Li 2017-08-11 14:13:18 +08:00
parent ee15c2c296
commit 56a4fedda2
8 changed files with 71 additions and 4 deletions

View File

@ -244,6 +244,9 @@ public interface MetricsRegionServerSource extends BaseSource, JvmPauseMonitorSo
String TOTAL_REQUEST_COUNT = "totalRequestCount"; String TOTAL_REQUEST_COUNT = "totalRequestCount";
String TOTAL_REQUEST_COUNT_DESC = String TOTAL_REQUEST_COUNT_DESC =
"Total number of requests this RegionServer has answered."; "Total number of requests this RegionServer has answered.";
String TOTAL_ROW_ACTION_REQUEST_COUNT = "totalRowActionRequestCount";
String TOTAL_ROW_ACTION_REQUEST_COUNT_DESC =
"Total number of region requests this RegionServer has answered, count by row-level action";
String READ_REQUEST_COUNT = "readRequestCount"; String READ_REQUEST_COUNT = "readRequestCount";
String READ_REQUEST_COUNT_DESC = String READ_REQUEST_COUNT_DESC =
"Number of read requests this region server has answered."; "Number of read requests this region server has answered.";

View File

@ -457,4 +457,6 @@ public interface MetricsRegionServerWrapper {
long getDeleteFamilyBloomHitCount(); long getDeleteFamilyBloomHitCount();
long getTrailerHitCount(); long getTrailerHitCount();
long getTotalRowActionRequestCount();
} }

View File

@ -354,6 +354,8 @@ public class MetricsRegionServerSourceImpl
.addGauge(Interns.info(AVERAGE_REGION_SIZE, AVERAGE_REGION_SIZE_DESC), rsWrap.getAverageRegionSize()) .addGauge(Interns.info(AVERAGE_REGION_SIZE, AVERAGE_REGION_SIZE_DESC), rsWrap.getAverageRegionSize())
.addCounter(Interns.info(TOTAL_REQUEST_COUNT, TOTAL_REQUEST_COUNT_DESC), .addCounter(Interns.info(TOTAL_REQUEST_COUNT, TOTAL_REQUEST_COUNT_DESC),
rsWrap.getTotalRequestCount()) rsWrap.getTotalRequestCount())
.addCounter(Interns.info(TOTAL_ROW_ACTION_REQUEST_COUNT, TOTAL_ROW_ACTION_REQUEST_COUNT_DESC),
rsWrap.getTotalRowActionRequestCount())
.addCounter(Interns.info(READ_REQUEST_COUNT, READ_REQUEST_COUNT_DESC), .addCounter(Interns.info(READ_REQUEST_COUNT, READ_REQUEST_COUNT_DESC),
rsWrap.getReadRequestsCount()) rsWrap.getReadRequestsCount())
.addCounter(Interns.info(FILTERED_READ_REQUEST_COUNT, FILTERED_READ_REQUEST_COUNT_DESC), .addCounter(Interns.info(FILTERED_READ_REQUEST_COUNT, FILTERED_READ_REQUEST_COUNT_DESC),

View File

@ -218,6 +218,11 @@ class MetricsRegionServerWrapperImpl
return regionServer.rpcServices.requestCount.sum(); return regionServer.rpcServices.requestCount.sum();
} }
@Override
public long getTotalRowActionRequestCount() {
return regionServer.rpcServices.requestRowActionCount.sum();
}
@Override @Override
public int getSplitQueueSize() { public int getSplitQueueSize() {
if (this.regionServer.compactSplitThread == null) { if (this.regionServer.compactSplitThread == null) {

View File

@ -256,8 +256,13 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
static final int BATCH_ROWS_THRESHOLD_DEFAULT = 5000; static final int BATCH_ROWS_THRESHOLD_DEFAULT = 5000;
// Request counter. (Includes requests that are not serviced by regions.) // Request counter. (Includes requests that are not serviced by regions.)
// Count only once for requests with multiple actions like multi/caching-scan/replayBatch
final LongAdder requestCount = new LongAdder(); final LongAdder requestCount = new LongAdder();
// Request counter. (Excludes requests that are not serviced by regions.)
// Count rows for requests with multiple actions like multi/caching-scan/replayBatch
final LongAdder requestRowActionCount = new LongAdder();
// Request counter for rpc get // Request counter for rpc get
final LongAdder rpcGetRequestCount = new LongAdder(); final LongAdder rpcGetRequestCount = new LongAdder();
@ -1091,7 +1096,8 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
it.remove(); it.remove();
} }
} }
requestCount.add(mutations.size()); requestCount.increment();
requestRowActionCount.add(mutations.size());
if (!region.getRegionInfo().isMetaTable()) { if (!region.getRegionInfo().isMetaTable()) {
regionServer.cacheFlusher.reclaimMemStoreMemory(); regionServer.cacheFlusher.reclaimMemStoreMemory();
} }
@ -2393,6 +2399,7 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
try { try {
checkOpen(); checkOpen();
requestCount.increment(); requestCount.increment();
requestRowActionCount.increment();
rpcGetRequestCount.increment(); rpcGetRequestCount.increment();
Region region = getRegion(request.getRegion()); Region region = getRegion(request.getRegion());
@ -2549,11 +2556,12 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
RegionScannersCloseCallBack closeCallBack = null; RegionScannersCloseCallBack closeCallBack = null;
RpcCallContext context = RpcServer.getCurrentCall(); RpcCallContext context = RpcServer.getCurrentCall();
this.rpcMultiRequestCount.increment(); this.rpcMultiRequestCount.increment();
this.requestCount.increment();
Map<RegionSpecifier, ClientProtos.RegionLoadStats> regionStats = new HashMap<>(request Map<RegionSpecifier, ClientProtos.RegionLoadStats> regionStats = new HashMap<>(request
.getRegionActionCount()); .getRegionActionCount());
ActivePolicyEnforcement spaceQuotaEnforcement = getSpaceQuotaManager().getActiveEnforcements(); ActivePolicyEnforcement spaceQuotaEnforcement = getSpaceQuotaManager().getActiveEnforcements();
for (RegionAction regionAction : request.getRegionActionList()) { for (RegionAction regionAction : request.getRegionActionList()) {
this.requestCount.add(regionAction.getActionCount()); this.requestRowActionCount.add(regionAction.getActionCount());
OperationQuota quota; OperationQuota quota;
Region region; Region region;
regionActionResultBuilder.clear(); regionActionResultBuilder.clear();
@ -2687,6 +2695,7 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
try { try {
checkOpen(); checkOpen();
requestCount.increment(); requestCount.increment();
requestRowActionCount.increment();
rpcMutateRequestCount.increment(); rpcMutateRequestCount.increment();
Region region = getRegion(request.getRegion()); Region region = getRegion(request.getRegion());
MutateResponse.Builder builder = MutateResponse.newBuilder(); MutateResponse.Builder builder = MutateResponse.newBuilder();
@ -3133,6 +3142,7 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
} }
} }
region.updateReadRequestsCount(numOfResults); region.updateReadRequestsCount(numOfResults);
requestRowActionCount.add(numOfResults);
long end = EnvironmentEdgeManager.currentTime(); long end = EnvironmentEdgeManager.currentTime();
long responseCellSize = context != null ? context.getResponseCellSize() : 0; long responseCellSize = context != null ? context.getResponseCellSize() : 0;
region.getMetrics().updateScanTime(end - before); region.getMetrics().updateScanTime(end - before);

View File

@ -100,6 +100,11 @@ public class MetricsRegionServerWrapperStub implements MetricsRegionServerWrappe
return 899; return 899;
} }
@Override
public long getTotalRowActionRequestCount() {
return getReadRequestsCount() + getWriteRequestsCount();
}
@Override @Override
public long getReadRequestsCount() { public long getReadRequestsCount() {
return 997; return 997;

View File

@ -72,6 +72,10 @@ public class TestMetricsRegionServer {
HELPER.assertGauge("memstoreSize", 1025, serverSource); HELPER.assertGauge("memstoreSize", 1025, serverSource);
HELPER.assertGauge("storeFileSize", 1900, serverSource); HELPER.assertGauge("storeFileSize", 1900, serverSource);
HELPER.assertCounter("totalRequestCount", 899, serverSource); HELPER.assertCounter("totalRequestCount", 899, serverSource);
HELPER.assertCounter("totalRowActionRequestCount",
HELPER.getCounter("readRequestCount", serverSource)
+ HELPER.getCounter("writeRequestCount", serverSource),
serverSource);
HELPER.assertCounter("readRequestCount", 997, serverSource); HELPER.assertCounter("readRequestCount", 997, serverSource);
HELPER.assertCounter("filteredReadRequestCount", 1997, serverSource); HELPER.assertCounter("filteredReadRequestCount", 1997, serverSource);
HELPER.assertCounter("writeRequestCount", 707, serverSource); HELPER.assertCounter("writeRequestCount", 707, serverSource);

View File

@ -224,6 +224,21 @@ public class TestRegionServerMetrics {
} }
} }
public void doScan(int n, boolean caching) throws IOException {
Scan scan = new Scan();
if (caching) {
scan.setCaching(n);
} else {
scan.setCaching(1);
}
ResultScanner scanner = table.getScanner(scan);
for (int i = 0; i < n; i++) {
Result res = scanner.next();
LOG.debug(
"Result row: " + Bytes.toString(res.getRow()) + ", value: " + res.getValue(cf, qualifier));
}
}
@Test @Test
public void testRegionCount() throws Exception { public void testRegionCount() throws Exception {
metricsHelper.assertGauge("regionCount", 1, serverSource); metricsHelper.assertGauge("regionCount", 1, serverSource);
@ -242,6 +257,7 @@ public class TestRegionServerMetrics {
metricsRegionServer.getRegionServerWrapper().forceRecompute(); metricsRegionServer.getRegionServerWrapper().forceRecompute();
long requests = metricsHelper.getCounter("totalRequestCount", serverSource); long requests = metricsHelper.getCounter("totalRequestCount", serverSource);
long rowActionRequests = metricsHelper.getCounter("totalRowActionRequestCount", serverSource);
long readRequests = metricsHelper.getCounter("readRequestCount", serverSource); long readRequests = metricsHelper.getCounter("readRequestCount", serverSource);
long writeRequests = metricsHelper.getCounter("writeRequestCount", serverSource); long writeRequests = metricsHelper.getCounter("writeRequestCount", serverSource);
@ -249,6 +265,7 @@ public class TestRegionServerMetrics {
metricsRegionServer.getRegionServerWrapper().forceRecompute(); metricsRegionServer.getRegionServerWrapper().forceRecompute();
assertCounter("totalRequestCount", requests + 30); assertCounter("totalRequestCount", requests + 30);
assertCounter("totalRowActionRequestCount", rowActionRequests + 30);
assertCounter("readRequestCount", readRequests); assertCounter("readRequestCount", readRequests);
assertCounter("writeRequestCount", writeRequests + 30); assertCounter("writeRequestCount", writeRequests + 30);
@ -256,6 +273,7 @@ public class TestRegionServerMetrics {
metricsRegionServer.getRegionServerWrapper().forceRecompute(); metricsRegionServer.getRegionServerWrapper().forceRecompute();
assertCounter("totalRequestCount", requests + 40); assertCounter("totalRequestCount", requests + 40);
assertCounter("totalRowActionRequestCount", rowActionRequests + 40);
assertCounter("readRequestCount", readRequests + 10); assertCounter("readRequestCount", readRequests + 10);
assertCounter("writeRequestCount", writeRequests + 30); assertCounter("writeRequestCount", writeRequests + 30);
@ -265,16 +283,34 @@ public class TestRegionServerMetrics {
doNGets(10, true); // true = batch doNGets(10, true); // true = batch
metricsRegionServer.getRegionServerWrapper().forceRecompute(); metricsRegionServer.getRegionServerWrapper().forceRecompute();
assertCounter("totalRequestCount", requests + 50); assertCounter("totalRequestCount", requests + 41);
assertCounter("totalRowActionRequestCount", rowActionRequests + 50);
assertCounter("readRequestCount", readRequests + 20); assertCounter("readRequestCount", readRequests + 20);
assertCounter("writeRequestCount", writeRequests + 30); assertCounter("writeRequestCount", writeRequests + 30);
doNPuts(30, true); doNPuts(30, true);
metricsRegionServer.getRegionServerWrapper().forceRecompute(); metricsRegionServer.getRegionServerWrapper().forceRecompute();
assertCounter("totalRequestCount", requests + 80); assertCounter("totalRequestCount", requests + 42);
assertCounter("totalRowActionRequestCount", rowActionRequests + 80);
assertCounter("readRequestCount", readRequests + 20); assertCounter("readRequestCount", readRequests + 20);
assertCounter("writeRequestCount", writeRequests + 60); assertCounter("writeRequestCount", writeRequests + 60);
doScan(10, false); // test after batch put so we have enough lines
metricsRegionServer.getRegionServerWrapper().forceRecompute();
assertCounter("totalRequestCount", requests + 52);
assertCounter("totalRowActionRequestCount", rowActionRequests + 90);
assertCounter("readRequestCount", readRequests + 30);
assertCounter("writeRequestCount", writeRequests + 60);
numScanNext += 10;
doScan(10, true); // true = caching
metricsRegionServer.getRegionServerWrapper().forceRecompute();
assertCounter("totalRequestCount", requests + 53);
assertCounter("totalRowActionRequestCount", rowActionRequests + 100);
assertCounter("readRequestCount", readRequests + 40);
assertCounter("writeRequestCount", writeRequests + 60);
numScanNext += 1;
} }
@Test @Test