You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/09/28 03:40:48 UTC

[GitHub] [dubbo] changfubai commented on a change in pull request #8916: [Dubbo-5961] Improve consistent hashing load balancing with a new algorithm #5989

changfubai commented on a change in pull request #8916:
URL: https://github.com/apache/dubbo/pull/8916#discussion_r717169435



##########
File path: dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java
##########
@@ -111,13 +149,49 @@ private String toKey(Object[] args) {
         }
 
         private Invoker<T> selectForKey(long hash) {
+            ++totalRequestCount;

Review comment:
       change to AtomicInteger to prevent concurrent problem?

##########
File path: dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java
##########
@@ -111,13 +149,49 @@ private String toKey(Object[] args) {
         }
 
         private Invoker<T> selectForKey(long hash) {
+            ++totalRequestCount;
             Map.Entry<Long, Invoker<T>> entry = virtualInvokers.ceilingEntry(hash);
             if (entry == null) {
                 entry = virtualInvokers.firstEntry();
             }
+            String serverAddress = entry.getValue().getUrl().getAddress();
+            double overloadThread = ((double) totalRequestCount / (double) serverCount) * overloadRatioAllowed;
+
+            /**
+             * 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)
+                    && serverRequestCountMap.get(serverAddress) >= overloadThread) {
+                /**
+                 * If server node is not valid, get next node
+                 */
+                entry = virtualInvokers.higherEntry(entry.getKey());
+                if(entry == null){
+                    entry = virtualInvokers.firstEntry();

Review comment:
       why not invoke method `getNextInvokerNode`?




-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org