Skip to content

Commit 474c8c6

Browse files
committed
HDFS-17709. [ARR] Add async responder performance metrics.
1 parent 6e43e60 commit 474c8c6

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/protocolPB/AsyncRpcProtocolPBUtil.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.hadoop.hdfs.protocolPB;
2020

21+
import org.apache.hadoop.hdfs.server.federation.metrics.FederationRPCMetrics;
2122
import org.apache.hadoop.hdfs.server.federation.router.ThreadLocalContext;
2223
import org.apache.hadoop.hdfs.server.federation.router.async.utils.ApplyFunction;
2324
import org.apache.hadoop.hdfs.server.federation.router.async.utils.AsyncUtil;
@@ -28,6 +29,7 @@
2829
import org.apache.hadoop.ipc.ProtobufRpcEngineCallback2;
2930
import org.apache.hadoop.ipc.internal.ShadedProtobufHelper;
3031
import org.apache.hadoop.thirdparty.protobuf.Message;
32+
import org.apache.hadoop.util.Time;
3133
import org.apache.hadoop.util.concurrent.AsyncGet;
3234
import org.slf4j.Logger;
3335
import org.slf4j.LoggerFactory;
@@ -87,6 +89,7 @@ public static <T, R> R asyncIpcClient(
8789
// transfer thread local context to worker threads of executor.
8890
ThreadLocalContext threadLocalContext = new ThreadLocalContext();
8991
asyncCompleteWith(responseFuture.handleAsync((result, e) -> {
92+
FederationRPCMetrics.ASYNC_RESPONDER_START_TIME.set(Time.monotonicNow());
9093
threadLocalContext.transfer();
9194
if (e != null) {
9295
throw warpCompletionException(e);
@@ -136,6 +139,7 @@ public static <T> void asyncRouterServer(ServerReq<T> req, ServerRes<T> res) {
136139
} else {
137140
callback.error(e.getCause());
138141
}
142+
FederationRPCMetrics.addAsyncResponderThreadTime();
139143
return null;
140144
});
141145
}

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/FederationRPCMetrics.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.hadoop.metrics2.lib.MetricsRegistry;
3131
import org.apache.hadoop.metrics2.lib.MutableCounterLong;
3232
import org.apache.hadoop.metrics2.lib.MutableRate;
33+
import org.apache.hadoop.util.Time;
3334

3435
/**
3536
* Implementation of the RPC metrics collector.
@@ -41,9 +42,15 @@ public class FederationRPCMetrics implements FederationRPCMBean {
4142
private final MetricsRegistry registry = new MetricsRegistry("router");
4243

4344
private RouterRpcServer rpcServer;
45+
public static final ThreadLocal<Long> ASYNC_RESPONDER_START_TIME =
46+
ThreadLocal.withInitial(() -> -1L);
47+
public static final ThreadLocal<Long> ASYNC_RESPONDER_END_TIME =
48+
ThreadLocal.withInitial(() -> -1L);
4449

4550
@Metric("Time for the router to process an operation internally")
4651
private MutableRate processing;
52+
@Metric("Time for the router async responder to process an operation internally")
53+
private static MutableRate asyncResponderProcessing;
4754
@Metric("Number of operations the Router processed internally")
4855
private MutableCounterLong processingOp;
4956
@Metric("Time for the Router to proxy an operation to the Namenodes")
@@ -302,6 +309,20 @@ public void addProcessingTime(long time) {
302309
processingOp.incr();
303310
}
304311

312+
public static void addAsyncResponderThreadTime() {
313+
ASYNC_RESPONDER_END_TIME.set(Time.monotonicNow());
314+
long duration = getAsyncResponderProcessingTime();
315+
asyncResponderProcessing.add(duration);
316+
}
317+
318+
public static long getAsyncResponderProcessingTime() {
319+
if (ASYNC_RESPONDER_START_TIME.get() != null && ASYNC_RESPONDER_START_TIME.get() > 0 &&
320+
ASYNC_RESPONDER_END_TIME.get() != null && ASYNC_RESPONDER_END_TIME.get() > 0) {
321+
return ASYNC_RESPONDER_END_TIME.get() - ASYNC_RESPONDER_START_TIME.get();
322+
}
323+
return -1;
324+
}
325+
305326
@Override
306327
public double getProcessingAvg() {
307328
return processing.lastStat().mean();

0 commit comments

Comments
 (0)