diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveLoadBalance.java index 29ee458f9e3e..095d3c39881e 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveLoadBalance.java @@ -39,8 +39,8 @@ protected Invoker doSelect(List> invokers, URL url, Invocation int leastActive = -1; // The least active value of all invokers int leastCount = 0; // The number of invokers having the same least active value (leastActive) int[] leastIndexs = new int[length]; // The index of invokers having the same least active value (leastActive) - int taotalWeightWithWarmUp = 0; // The sum of with warmup weights - int firstWeightWithWarmUp = 0; // Initial value, used for comparision + int totalWeight = 0; // The sum of with warmup weights + int firstWeight = 0; // Initial value, used for comparision boolean sameWeight = true; // Every invoker has the same weight value? for (int i = 0; i < length; i++) { Invoker invoker = invokers.get(i); @@ -50,15 +50,15 @@ protected Invoker doSelect(List> invokers, URL url, Invocation leastActive = active; // Record the current least active value leastCount = 1; // Reset leastCount, count again based on current leastCount leastIndexs[0] = i; // Reset - taotalWeightWithWarmUp = afterWarmup; // Reset - firstWeightWithWarmUp = afterWarmup; // Record the weight the first invoker + totalWeight = afterWarmup; // Reset + firstWeight = afterWarmup; // Record the weight the first invoker sameWeight = true; // Reset, every invoker has the same weight value? } else if (active == leastActive) { // If current invoker's active value equals with leaseActive, then accumulating. leastIndexs[leastCount++] = i; // Record index number of this invoker - taotalWeightWithWarmUp += afterWarmup; // Add this invoker's with warmup weight to totalWeightWithWarmUp. + totalWeight += afterWarmup; // Add this invoker's with warmup weight to totalWeight. // If every invoker has the same weight? if (sameWeight && i > 0 - && afterWarmup != firstWeightWithWarmUp) { + && afterWarmup != firstWeight) { sameWeight = false; } } @@ -68,9 +68,9 @@ protected Invoker doSelect(List> invokers, URL url, Invocation // If we got exactly one invoker having the least active value, return this invoker directly. return invokers.get(leastIndexs[0]); } - if (!sameWeight && taotalWeightWithWarmUp > 0) { - // If (not every invoker has the same weight & at least one invoker's weight>0), select randomly based on totalWeightWithWarmUp. - int offsetWeight = random.nextInt(taotalWeightWithWarmUp) + 1; + if (!sameWeight && totalWeight > 0) { + // If (not every invoker has the same weight & at least one invoker's weight>0), select randomly based on totalWeight. + int offsetWeight = random.nextInt(totalWeight) + 1; // Return a invoker based on the random value. for (int i = 0; i < leastCount; i++) { int leastIndex = leastIndexs[i]; @@ -79,7 +79,7 @@ protected Invoker doSelect(List> invokers, URL url, Invocation return invokers.get(leastIndex); } } - // If all invokers have the same weight value or totalWeightWithWarmUp=0, return evenly. + // If all invokers have the same weight value or totalWeight=0, return evenly. return invokers.get(leastIndexs[random.nextInt(leastCount)]); } }