-
Notifications
You must be signed in to change notification settings - Fork 3.9k
A68 random subsetting #12377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
A68 random subsetting #12377
Conversation
9178308
to
aefee00
Compare
aefee00
to
1870e6f
Compare
resolvedAddresses.getLoadBalancingPolicyConfig(); | ||
|
||
ResolvedAddresses subsetAddresses = filterEndpoints( | ||
resolvedAddresses, config.subsetSize, new SecureRandom().nextLong()); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
implementing gRFC A65 grpc/proposal/pull/423
This change contains:
XxHash64
library, so it can be shared betweenutil
andxds
projects. Proposed source directory is:third-party/zero-allocation-hashing
.RandomSubsettingLoadBalancer
andRandomSubsettingLoadBalancerProvider
classes and integrated them intoutil
project.random_subsetting
LB policy and as well new envoy proto message.