This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch 3.x-dev
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git


The following commit(s) were added to refs/heads/3.x-dev by this push:
     new 0d0ad0a  performance improve for DefaultFuture and AsyncToSyncInvoker 
(#4085)
0d0ad0a is described below

commit 0d0ad0ab6407fca9ca22b10fb6edb96eaea97992
Author: jefflv <[email protected]>
AuthorDate: Tue May 21 14:50:25 2019 +0800

    performance improve for DefaultFuture and AsyncToSyncInvoker (#4085)
---
 .gitignore                                         |  1 +
 .../remoting/exchange/support/DefaultFuture.java   | 32 ++++++++++++----------
 .../dubbo/rpc/protocol/AsyncToSyncInvoker.java     |  3 +-
 3 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/.gitignore b/.gitignore
index a98a8a6..b4467e7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,7 @@ target/
 *.zip
 *.tar
 *.tar.gz
+.flattened-pom.xml
 
 # eclipse ignore
 .settings/
diff --git 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
index 8385f54..f7b5239 100644
--- 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
+++ 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
@@ -50,7 +50,7 @@ public class DefaultFuture extends CompletableFuture<Object> {
 
     private static final Map<Long, DefaultFuture> FUTURES = new 
ConcurrentHashMap<>();
 
-    private static final Map<Long, Timeout> PENDING_TASKS = new 
ConcurrentHashMap<>();
+//    private static final Map<Long, Timeout> PENDING_TASKS = new 
ConcurrentHashMap<>();
 
     public static final Timer TIME_OUT_TIMER = new HashedWheelTimer(
             new NamedThreadFactory("dubbo-future-timeout", true),
@@ -58,7 +58,7 @@ public class DefaultFuture extends CompletableFuture<Object> {
             TimeUnit.MILLISECONDS);
 
     // invoke id.
-    private final long id;
+    private final Long id;
     private final Channel channel;
     private final Request request;
     private final int timeout;
@@ -146,11 +146,11 @@ public class DefaultFuture extends 
CompletableFuture<Object> {
             DefaultFuture future = FUTURES.remove(response.getId());
             if (future != null) {
                 future.doReceived(response);
-                Timeout t = PENDING_TASKS.remove(future.getId());
-                if (t != null) {
-                    // decrease Time
-                    t.cancel();
-                }
+//                Timeout t = PENDING_TASKS.remove(future.getId());
+//                if (t != null) {
+//                    // decrease Time
+//                    t.cancel();
+//                }
             } else {
                 logger.warn("The timeout response finally returned at "
                         + (new SimpleDateFormat("yyyy-MM-dd 
HH:mm:ss.SSS").format(new Date()))
@@ -228,10 +228,11 @@ public class DefaultFuture extends 
CompletableFuture<Object> {
      * check time out of the future
      */
     private static void timeoutCheck(DefaultFuture future) {
-        TimeoutCheckTask task = new TimeoutCheckTask(future);
-        Timeout t = TIME_OUT_TIMER.newTimeout(task, future.getTimeout(), 
TimeUnit.MILLISECONDS);
-        PENDING_TASKS.put(future.getId(), t);
+        TimeoutCheckTask task = new TimeoutCheckTask(future.getId());
+        TIME_OUT_TIMER.newTimeout(task, future.getTimeout(), 
TimeUnit.MILLISECONDS);
+//        PENDING_TASKS.put(future.getId(), t);
     }
+
     private String getTimeoutMessage(boolean scan) {
         long nowTimestamp = System.currentTimeMillis();
         return (sent > 0 ? "Waiting server-side response timeout" : "Sending 
request timeout in client-side")
@@ -247,18 +248,19 @@ public class DefaultFuture extends 
CompletableFuture<Object> {
 
     private static class TimeoutCheckTask implements TimerTask {
 
-        private DefaultFuture future;
+        private final Long requestID;
 
-        TimeoutCheckTask(DefaultFuture future) {
-            this.future = future;
+        TimeoutCheckTask(Long requestID) {
+            this.requestID = requestID;
         }
 
         @Override
         public void run(Timeout timeout) {
             // remove from pending task
-            PENDING_TASKS.remove(future.getId());
+//            PENDING_TASKS.remove(future.getId());
 
-            if (future.isDone()) {
+            DefaultFuture future = FUTURES.remove(requestID);
+            if (future == null || future.isDone()) {
                 return;
             }
             if (future.getExecutor() != null) {
diff --git 
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AsyncToSyncInvoker.java
 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AsyncToSyncInvoker.java
index 5c06b4e..9f1725d 100644
--- 
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AsyncToSyncInvoker.java
+++ 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AsyncToSyncInvoker.java
@@ -27,6 +27,7 @@ import org.apache.dubbo.rpc.RpcException;
 import org.apache.dubbo.rpc.RpcInvocation;
 
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
 
 /**
  * This class will work as a wrapper wrapping outside of each protocol invoker.
@@ -51,7 +52,7 @@ public class AsyncToSyncInvoker<T> implements Invoker<T> {
 
         try {
             if (InvokeMode.SYNC == 
((RpcInvocation)invocation).getInvokeMode()) {
-                asyncResult.get();
+                
asyncResult.get(invoker.getUrl().getMethodParameter(invocation.getMethodName(), 
"timeout", 1000), TimeUnit.MILLISECONDS);
             }
         } catch (InterruptedException e) {
             throw new RpcException("Interrupted unexpectedly while waiting for 
remoting result to return!  method: " + invocation.getMethodName() + ", 
provider: " + getUrl() + ", cause: " + e.getMessage(), e);

Reply via email to