Optimize synchronized in PartitionedDispatcher (#8640)
Even if the `PartitionedDispatcher.populatedPartitions()` is fast, in-memory, non-blocking operation, its active call from the `dispatch()` on every message sent to the channel may pin the virtual thread. * Optimize the `populatedPartitions()` for double `if` where we will step into a `synchronized` block only for first several concurrent messages **Cherry-pick to `6.1.x`**
This commit is contained in:
@@ -151,10 +151,16 @@ public class PartitionedDispatcher extends AbstractDispatcher {
|
||||
return partitionDispatcher.dispatch(message);
|
||||
}
|
||||
|
||||
private synchronized void populatedPartitions() {
|
||||
private void populatedPartitions() {
|
||||
if (this.partitions.isEmpty()) {
|
||||
for (int i = 0; i < this.partitionCount; i++) {
|
||||
this.partitions.put(i, newPartition());
|
||||
synchronized (this.partitions) {
|
||||
if (this.partitions.isEmpty()) {
|
||||
Map<Integer, UnicastingDispatcher> partitionsToUse = new HashMap<>();
|
||||
for (int i = 0; i < this.partitionCount; i++) {
|
||||
partitionsToUse.put(i, newPartition());
|
||||
}
|
||||
this.partitions.putAll(partitionsToUse);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user