xiaotongwang1 commented on code in PR #8948:
URL: https://github.com/apache/dubbo/pull/8948#discussion_r897464071


##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java:
##########
@@ -110,15 +141,61 @@ private String toKey(Object[] args) {
             }
             return buf.toString();
         }
-
         private Invoker<T> selectForKey(long hash) {
             Map.Entry<Long, Invoker<T>> entry = 
virtualInvokers.ceilingEntry(hash);
             if (entry == null) {
                 entry = virtualInvokers.firstEntry();
             }
+
+            String serverAddress = entry.getValue().getUrl().getAddress();
+
+            /**
+             * The following part of codes aims to select suitable invoker.
+             * This part is not complete thread safety.
+             * However, in the scene of consumer-side load balance,
+             * thread race for this part of codes
+             * (execution time cost for this part of codes without any IO or
+             * network operation is very low) will rarely occur. And even in
+             * extreme case, a few requests are assigned to an invoker which
+             * is above OVERLOAD_RATIO_THREAD will not make a significant 
impact
+             * on the effect of this new algorithm.
+             * And make this part of codes synchronized will reduce efficiency 
of
+             * every request. In my opinion, this is not worth. So it is not a
+             * problem for this part is not complete thread safety.
+             */
+            double overloadThread = ((double) totalRequestCount.get() / 
(double) serverCount) * OVERLOAD_RATIO_THREAD;
+            /**
+             * Find a valid server node:
+             * 1. Not have accept request yet
+             * or
+             * 2. Not have overloaded (request count already accept < thread 
(average request count * overloadRatioAllowed ))
+             */
+            while (serverRequestCountMap.containsKey(serverAddress)

Review Comment:
   可能导致死循环



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to