Skip to content

Conversation

Zgoda91
Copy link

@Zgoda91 Zgoda91 commented Sep 24, 2025

implementing gRFC A65 grpc/proposal/pull/423

This change contains:

  1. Relocation of XxHash64 library, so it can be shared between util and xds projects. Proposed source directory is: third-party/zero-allocation-hashing.
  2. Implemented RandomSubsettingLoadBalancer and RandomSubsettingLoadBalancerProvider classes and integrated them into util project.
  3. Implemented xDS conversion function for random_subsetting LB policy and as well new envoy proto message.

@Zgoda91 Zgoda91 force-pushed the A68_random_subsetting branch from 9178308 to aefee00 Compare September 24, 2025 12:26
@Zgoda91 Zgoda91 force-pushed the A68_random_subsetting branch from aefee00 to 1870e6f Compare September 24, 2025 13:57
resolvedAddresses.getLoadBalancingPolicyConfig();

ResolvedAddresses subsetAddresses = filterEndpoints(
resolvedAddresses, config.subsetSize, new SecureRandom().nextLong());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same seed should be used for the life of the policy. When the addresses don't change much, we don't want the chosen subset to change much. If we change the seed every time, we'll always get vastly different results, even with the same input.

resolvedAddresses.getLoadBalancingPolicyConfig();

ResolvedAddresses subsetAddresses = filterEndpoints(
resolvedAddresses, config.subsetSize, new SecureRandom().nextLong());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not cryptographically hashing, so Random is fine; no need for SecureRandom.


Collections.sort(endpointWithHashList, new HashAddressComparator());

ArrayList<EquivalentAddressGroup> addressGroups = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass subsetSize to the ArrayList constructor, to reduce the number of allocations and final memory use.

* https://https://github.com/grpc/proposal/blob/master/A68-random-subsetting.md
*/
@Internal
public final class RandomSubsettingLoadBalancer extends LoadBalancer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package-private? I don't see a need for it to be public.

include ":grpc-util"
include ":grpc-opentelemetry"
include ":grpc-context-override-opentelemetry"
include ":grpc-third-party:zero-allocation-hashing"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to create a new artifact for this; that causes a lot of head-ache and lasts forever. xxhash is small enough that I'd sooner move it to grpc-core. The other option would be to use com.google.common.hash.Hashing, probably murmur3_128. xxhash has the zero-allocation implementation quite fitting for our use-case, but Guava's would probably be fine. We can always change it in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants