diff --git a/pom.xml b/pom.xml
index 5982049a..d4d0c5f7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
4.0.0com.alipay.sofabolt
- 1.5.8
+ 1.5.9jar${project.groupId}:${project.artifactId}
diff --git a/src/main/java/com/alipay/remoting/BaseRemoting.java b/src/main/java/com/alipay/remoting/BaseRemoting.java
index 519f890e..cd30c56d 100644
--- a/src/main/java/com/alipay/remoting/BaseRemoting.java
+++ b/src/main/java/com/alipay/remoting/BaseRemoting.java
@@ -61,6 +61,10 @@ protected RemotingCommand invokeSync(final Connection conn, final RemotingComman
final InvokeFuture future = createInvokeFuture(request, request.getInvokeContext());
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() {
@@ -75,6 +79,10 @@ public void operationComplete(ChannelFuture f) throws Exception {
}
});
+
+ if (null != invokeContext) {
+ invokeContext.put(InvokeContext.BOLT_PROCESS_CLIENT_AFTER_SEND, System.nanoTime());
+ }
} catch (Exception e) {
conn.removeInvokeFuture(requestId);
future.putResponse(commandFactory.createSendFailedResponse(conn.getRemoteAddress(), e));
@@ -82,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 6aae5614..13beede5 100644
--- a/src/main/java/com/alipay/remoting/InvokeContext.java
+++ b/src/main/java/com/alipay/remoting/InvokeContext.java
@@ -26,28 +26,47 @@
*/
public class InvokeContext {
// ~~~ invoke context keys of client side
- public final static String CLIENT_LOCAL_IP = "bolt.client.local.ip";
- public final static String CLIENT_LOCAL_PORT = "bolt.client.local.port";
- public final static String CLIENT_REMOTE_IP = "bolt.client.remote.ip";
- public final static String CLIENT_REMOTE_PORT = "bolt.client.remote.port";
+ public final static String CLIENT_LOCAL_IP = "bolt.client.local.ip";
+ public final static String CLIENT_LOCAL_PORT = "bolt.client.local.port";
+ public final static String CLIENT_REMOTE_IP = "bolt.client.remote.ip";
+ public final static String CLIENT_REMOTE_PORT = "bolt.client.remote.port";
/** time consumed during connection creating, this is a timespan */
- public final static String CLIENT_CONN_CREATETIME = "bolt.client.conn.createtime";
+ public final static String CLIENT_CONN_CREATETIME = "bolt.client.conn.createtime";
+ public final static String CLIENT_CONN_CREATE_START_IN_NANO = "bolt.client.conn.create.start.nano";
+ public final static String CLIENT_CONN_CREATE_END_IN_NANO = "bolt.client.conn.create.end.nano";
// ~~~ invoke context keys of server side
- public final static String SERVER_LOCAL_IP = "bolt.server.local.ip";
- public final static String SERVER_LOCAL_PORT = "bolt.server.local.port";
- public final static String SERVER_REMOTE_IP = "bolt.server.remote.ip";
- public final static String SERVER_REMOTE_PORT = "bolt.server.remote.port";
+ public final static String SERVER_LOCAL_IP = "bolt.server.local.ip";
+ public final static String SERVER_LOCAL_PORT = "bolt.server.local.port";
+ public final static String SERVER_REMOTE_IP = "bolt.server.remote.ip";
+ public final static String SERVER_REMOTE_PORT = "bolt.server.remote.port";
// ~~~ invoke context keys of bolt client and server side
- public final static String BOLT_INVOKE_REQUEST_ID = "bolt.invoke.request.id";
+ public final static String BOLT_INVOKE_REQUEST_ID = "bolt.invoke.request.id";
/** time consumed start from the time when request arrive, to the time when request be processed, this is a timespan */
- public final static String BOLT_PROCESS_WAIT_TIME = "bolt.invoke.wait.time";
- public final static String BOLT_CUSTOM_SERIALIZER = "bolt.invoke.custom.serializer";
- public final static String BOLT_CRC_SWITCH = "bolt.invoke.crc.switch";
+ public final static String BOLT_PROCESS_WAIT_TIME = "bolt.invoke.wait.time";
+ /** time request arrived in nano seconds , collected by System.nanoTime() */
+ public final static String BOLT_PROCESS_ARRIVE_HEADER_IN_NANO = "bolt.invoke.request.arrive.header.in.nano";
+ public final static String BOLT_PROCESS_ARRIVE_BODY_IN_NANO = "bolt.invoke.request.arrive.body.in.nano";
+
+ /** time before send request to user thread in nano seconds , collected by System.nanoTime() */
+ public final static String BOLT_PROCESS_BEFORE_DISPATCH_IN_NANO = "bolt.invoke.before.dispatch.in.nano";
+
+ /** time before send request to user thread in nano seconds , collected by System.nanoTime() */
+ public final static String BOLT_PROCESS_START_PROCESS_IN_NANO = "bolt.invoke.start.process.in.nano";
+
+ 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;
+ public final static int INITIAL_SIZE = 8;
/** context */
private ConcurrentHashMap context;
diff --git a/src/main/java/com/alipay/remoting/config/switches/ProtocolSwitch.java b/src/main/java/com/alipay/remoting/config/switches/ProtocolSwitch.java
index b85f29ab..ac91a17a 100644
--- a/src/main/java/com/alipay/remoting/config/switches/ProtocolSwitch.java
+++ b/src/main/java/com/alipay/remoting/config/switches/ProtocolSwitch.java
@@ -127,8 +127,8 @@ public static byte toByte(BitSet bs) {
public static BitSet toBitSet(int value) {
if (value < 0 || value > Byte.MAX_VALUE) {
throw new IllegalArgumentException(
- "The value " + value + " is out of byte range, should be limited between ["
- + 0 + "] to [" + Byte.MAX_VALUE + "]");
+ "The value " + value + " is out of byte range, should be limited between [" + 0
+ + "] to [" + Byte.MAX_VALUE + "]");
}
BitSet bs = new BitSet();
int index = 0;
diff --git a/src/main/java/com/alipay/remoting/rpc/RpcClientRemoting.java b/src/main/java/com/alipay/remoting/rpc/RpcClientRemoting.java
index 5a500e2b..84028ca2 100644
--- a/src/main/java/com/alipay/remoting/rpc/RpcClientRemoting.java
+++ b/src/main/java/com/alipay/remoting/rpc/RpcClientRemoting.java
@@ -29,7 +29,7 @@
/**
* Rpc client remoting
- *
+ *
* @author xiaomin.cxm
* @version $Id: RpcClientRemoting.java, v 0.1 Apr 14, 2016 11:58:56 AM xiaomin.cxm Exp $
*/
@@ -119,6 +119,8 @@ protected Connection getConnectionAndInitInvokeContext(Url url, InvokeContext in
throws RemotingException,
InterruptedException {
long start = System.currentTimeMillis();
+ long startInNano = System.nanoTime();
+
Connection conn;
try {
conn = this.connectionManager.getAndCreateIfAbsent(url);
@@ -126,6 +128,10 @@ protected Connection getConnectionAndInitInvokeContext(Url url, InvokeContext in
if (null != invokeContext) {
invokeContext.putIfAbsent(InvokeContext.CLIENT_CONN_CREATETIME,
(System.currentTimeMillis() - start));
+ invokeContext.putIfAbsent(InvokeContext.CLIENT_CONN_CREATE_START_IN_NANO,
+ startInNano);
+ invokeContext.putIfAbsent(InvokeContext.CLIENT_CONN_CREATE_END_IN_NANO,
+ System.nanoTime());
}
}
return conn;
diff --git a/src/main/java/com/alipay/remoting/rpc/protocol/RpcCommandDecoder.java b/src/main/java/com/alipay/remoting/rpc/protocol/RpcCommandDecoder.java
index 1618279d..a00fb58b 100644
--- a/src/main/java/com/alipay/remoting/rpc/protocol/RpcCommandDecoder.java
+++ b/src/main/java/com/alipay/remoting/rpc/protocol/RpcCommandDecoder.java
@@ -19,6 +19,8 @@
import java.net.InetSocketAddress;
import java.util.List;
+import com.alipay.remoting.util.ThreadLocalArriveTimeHolder;
+import io.netty.channel.Channel;
import org.slf4j.Logger;
import com.alipay.remoting.CommandCode;
@@ -96,6 +98,9 @@ public void decode(ChannelHandlerContext ctx, ByteBuf in, List