carryxyh commented on a change in pull request #2445: [Dubbo-2328]Fix the 
concurrency limit of 'ActiveLimitFilter' to calculate atomicity
URL: https://github.com/apache/incubator-dubbo/pull/2445#discussion_r221193759
 
 

 ##########
 File path: 
dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ActiveLimitFilter.java
 ##########
 @@ -37,30 +39,28 @@ public Result invoke(Invoker<?> invoker, Invocation 
invocation) throws RpcExcept
         URL url = invoker.getUrl();
         String methodName = invocation.getMethodName();
         int max = invoker.getUrl().getMethodParameter(methodName, 
Constants.ACTIVES_KEY, 0);
+        Semaphore activesLimit = null;
+        boolean acquireResult = false;
         RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), 
invocation.getMethodName());
         if (max > 0) {
             long timeout = 
invoker.getUrl().getMethodParameter(invocation.getMethodName(), 
Constants.TIMEOUT_KEY, 0);
             long start = System.currentTimeMillis();
-            long remain = timeout;
-            int active = count.getActive();
-            if (active >= max) {
-                synchronized (count) {
-                    while ((active = count.getActive()) >= max) {
-                        try {
-                            count.wait(remain);
-                        } catch (InterruptedException e) {
-                        }
-                        long elapsed = System.currentTimeMillis() - start;
-                        remain = timeout - elapsed;
-                        if (remain <= 0) {
-                            throw new RpcException("Waiting concurrent invoke 
timeout in client-side for service:  "
-                                    + invoker.getInterface().getName() + ", 
method: "
-                                    + invocation.getMethodName() + ", elapsed: 
" + elapsed
-                                    + ", timeout: " + timeout + ". concurrent 
invokes: " + active
-                                    + ". max concurrent invoke limit: " + max);
-                        }
-                    }
+            activesLimit = count.getActivesSemaphore(max);
+            try {
+                if(activesLimit != null && !(acquireResult = 
activesLimit.tryAcquire(timeout,TimeUnit.MILLISECONDS))) {
+                    long elapsed = System.currentTimeMillis() - start;
+                    int active=count.getActive();
 
 Review comment:
   need format, too.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to