Skip to content

Commit

Permalink
Shuffle DNS records before propagating to LoadBalancer (#2673)
Browse files Browse the repository at this point in the history
Motivation:

If multiple client instances receive identical DNS records set, they
will start connecting to the same upstream instances because the
collection is always sorter.

Modifications:

- Shuffle the list before propagating to the load balancer;

Result:

More uniform distribution of the initial connections.
  • Loading branch information
idelpivnitskiy authored Aug 16, 2023
1 parent b59ad76 commit d38e5fd
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -846,6 +847,10 @@ private void handleResolveDone0(final Future<DnsAnswer<T>> addressFuture,
cancellableForQuery = null;
}
try {
// Shuffle events to avoid multiple clients connecting to the same upstream IP address if
// they receive identical result set from DNS.
Collections.shuffle(events);

LOGGER.debug("{} sending events for {} (size={}, TTL={}s): {}.",
DefaultDnsClient.this, AbstractDnsPublisher.this, events.size(),
NANOSECONDS.toSeconds(ttlNanos), events);
Expand Down

0 comments on commit d38e5fd

Please sign in to comment.