From 55282376e748f73d35a46114d9edb86d8b41035f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9D=E6=9C=9B?= Date: Thu, 15 Jul 2021 11:56:38 +0800 Subject: [PATCH] support record client send time --- src/main/java/com/alipay/remoting/BaseRemoting.java | 9 ++++++++- src/main/java/com/alipay/remoting/InvokeContext.java | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/alipay/remoting/BaseRemoting.java b/src/main/java/com/alipay/remoting/BaseRemoting.java index b8fd5307..cd30c56d 100644 --- a/src/main/java/com/alipay/remoting/BaseRemoting.java +++ b/src/main/java/com/alipay/remoting/BaseRemoting.java @@ -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() { @@ -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); @@ -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()); diff --git a/src/main/java/com/alipay/remoting/InvokeContext.java b/src/main/java/com/alipay/remoting/InvokeContext.java index 4b8a94f3..13beede5 100644 --- a/src/main/java/com/alipay/remoting/InvokeContext.java +++ b/src/main/java/com/alipay/remoting/InvokeContext.java @@ -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;