Randomness is also needed when having only 2 nodes. If not it will always select [0] when pending is equal.
@@ -30,15 +30,11 @@ class AdaptiveLoadBalancer extends LoadBalancer {
entry = choices.get(0);
metrics = getNodeMetrics(entry);
} else {
- int candA = 0;
- int candB = 1;
- if (choices.size() > 2) {
- candA = random.nextInt(choices.size());
- candB = random.nextInt(choices.size());
+ int candA = random.nextInt(choices.size());
+ int candB = random.nextInt(choices.size());
while (candB == candA) {
candB = random.nextInt(choices.size());
}
- }
entry = choices.get(candA);
Mirror.Entry entryB = choices.get(candB);
metrics = getNodeMetrics(entry);
