Skip to content

Commit

Permalink
support record client send time
Browse files Browse the repository at this point in the history
  • Loading branch information
OrezzerO committed Jul 15, 2021
1 parent c7f62f8 commit 5528237
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/com/alipay/remoting/BaseRemoting.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ protected RemotingCommand invokeSync(final Connection conn, final RemotingComman
conn.addInvokeFuture(future);
final int requestId = request.getId();
InvokeContext invokeContext = request.getInvokeContext();
if (null != invokeContext) {
invokeContext.put(InvokeContext.BOLT_PROCESS_CLIENT_BEFORE_SEND, System.nanoTime());
}
try {
conn.getChannel().writeAndFlush(request).addListener(new ChannelFutureListener() {

Expand All @@ -78,7 +81,7 @@ public void operationComplete(ChannelFuture f) throws Exception {
});

if (null != invokeContext) {
invokeContext.put("REQUEST_SEND", System.nanoTime());
invokeContext.put(InvokeContext.BOLT_PROCESS_CLIENT_AFTER_SEND, System.nanoTime());
}
} catch (Exception e) {
conn.removeInvokeFuture(requestId);
Expand All @@ -87,6 +90,10 @@ public void operationComplete(ChannelFuture f) throws Exception {
}
RemotingCommand response = future.waitResponse(timeoutMillis);

if (null != invokeContext) {
invokeContext.put(InvokeContext.BOLT_PROCESS_CLIENT_RECEIVED, System.nanoTime());
}

if (response == null) {
conn.removeInvokeFuture(requestId);
response = this.commandFactory.createTimeoutResponse(conn.getRemoteAddress());
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/alipay/remoting/InvokeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public class InvokeContext {
public final static String BOLT_CUSTOM_SERIALIZER = "bolt.invoke.custom.serializer";
public final static String BOLT_CRC_SWITCH = "bolt.invoke.crc.switch";

/** time before send request to net in nano seconds , collected by System.nanoTime() **/
public final static String BOLT_PROCESS_CLIENT_BEFORE_SEND = "bolt.invoke.client.before.send";
/** time after send request to net in nano seconds , collected by System.nanoTime() **/
public final static String BOLT_PROCESS_CLIENT_AFTER_SEND = "bolt.invoke.client.after.send";
/** time after receive response from server in nano seconds , collected by System.nanoTime() **/
public final static String BOLT_PROCESS_CLIENT_RECEIVED = "bolt.invoke.client.received";

// ~~~ constants
public final static int INITIAL_SIZE = 8;

Expand Down

0 comments on commit 5528237

Please sign in to comment.