Skip to content

Commit

Permalink
TokenAwarePolicy: fix bad perf of ReplicaOrdering.RANDOM (#427)
Browse files Browse the repository at this point in the history
`ReplicaOrdering.RANDOM` shows up to `20%` worse throughput.
Switching from `java.util.Random `to `ThreadLocalRandom` showed `20%`
improvement.
  • Loading branch information
dkropachev authored Jan 27, 2025
1 parent 85ae66e commit 538fe6c
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;

/**
* A wrapper load balancing policy that adds token awareness to a child policy.
Expand Down Expand Up @@ -250,7 +251,7 @@ protected Host computeNext() {

if (replicaOrdering == ReplicaOrdering.RANDOM) {
List<Host> replicasList = Lists.newArrayList(replicas);
Collections.shuffle(replicasList);
Collections.shuffle(replicasList, ThreadLocalRandom.current());
replicasIterator = replicasList.iterator();
} else {
replicasIterator = replicas.iterator();
Expand Down

0 comments on commit 538fe6c

Please sign in to comment.