Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDFS-17709. [ARR] Add async responder and async handler performance metrics. #7292

Open
wants to merge 3 commits into
base: HDFS-17531
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.hadoop.hdfs.protocolPB;

import org.apache.hadoop.hdfs.server.federation.metrics.FederationRPCMetrics;
import org.apache.hadoop.hdfs.server.federation.router.ThreadLocalContext;
import org.apache.hadoop.hdfs.server.federation.router.async.utils.ApplyFunction;
import org.apache.hadoop.hdfs.server.federation.router.async.utils.AsyncUtil;
Expand All @@ -28,6 +29,7 @@
import org.apache.hadoop.ipc.ProtobufRpcEngineCallback2;
import org.apache.hadoop.ipc.internal.ShadedProtobufHelper;
import org.apache.hadoop.thirdparty.protobuf.Message;
import org.apache.hadoop.util.Time;
import org.apache.hadoop.util.concurrent.AsyncGet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -87,6 +89,7 @@ public static <T, R> R asyncIpcClient(
// transfer thread local context to worker threads of executor.
ThreadLocalContext threadLocalContext = new ThreadLocalContext();
asyncCompleteWith(responseFuture.handleAsync((result, e) -> {
FederationRPCMetrics.ASYNC_RESPONDER_START_TIME.set(Time.monotonicNow());
Comment on lines 90 to +92
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @hfutatzhanghb If thread local variables are used, it is recommended to use ThreadLocalContext, refer to startUpTime and proxyOpTime; because the response of a request may be processed by async responder or async handler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KeeProMise Sir, very nice suggestions. will fix it soon.

threadLocalContext.transfer();
if (e != null) {
throw warpCompletionException(e);
Expand Down Expand Up @@ -136,6 +139,7 @@ public static <T> void asyncRouterServer(ServerReq<T> req, ServerRes<T> res) {
} else {
callback.error(e.getCause());
}
FederationRPCMetrics.addAsyncResponderThreadTime();
return null;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.hadoop.metrics2.lib.MetricsRegistry;
import org.apache.hadoop.metrics2.lib.MutableCounterLong;
import org.apache.hadoop.metrics2.lib.MutableRate;
import org.apache.hadoop.util.Time;

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

private RouterRpcServer rpcServer;
public static final ThreadLocal<Long> ASYNC_RESPONDER_START_TIME =
ThreadLocal.withInitial(() -> -1L);
public static final ThreadLocal<Long> ASYNC_RESPONDER_END_TIME =
ThreadLocal.withInitial(() -> -1L);

@Metric("Time for the router to process an operation internally")
private MutableRate processing;
@Metric("Time for the router async responder to process an operation internally")
private static MutableRate asyncResponderProcessing;
@Metric("Number of operations the Router processed internally")
private MutableCounterLong processingOp;
@Metric("Time for the Router to proxy an operation to the Namenodes")
Expand Down Expand Up @@ -302,6 +309,20 @@ public void addProcessingTime(long time) {
processingOp.incr();
}

public static void addAsyncResponderThreadTime() {
ASYNC_RESPONDER_END_TIME.set(Time.monotonicNow());
long duration = getAsyncResponderProcessingTime();
asyncResponderProcessing.add(duration);
}

public static long getAsyncResponderProcessingTime() {
if (ASYNC_RESPONDER_START_TIME.get() != null && ASYNC_RESPONDER_START_TIME.get() > 0 &&
ASYNC_RESPONDER_END_TIME.get() != null && ASYNC_RESPONDER_END_TIME.get() > 0) {
return ASYNC_RESPONDER_END_TIME.get() - ASYNC_RESPONDER_START_TIME.get();
}
return -1;
}

@Override
public double getProcessingAvg() {
return processing.lastStat().mean();
Expand Down
Loading