Skip to content

Commit

Permalink
optimize typo
Browse files Browse the repository at this point in the history
  • Loading branch information
carryxyh committed Aug 16, 2018
1 parent c83eb58 commit e4fe009
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> 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<T> invoker = invokers.get(i);
Expand All @@ -50,15 +50,15 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> 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;
}
}
Expand All @@ -68,9 +68,9 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> 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];
Expand All @@ -79,7 +79,7 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> 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)]);
}
}

0 comments on commit e4fe009

Please sign in to comment.