A113: pick_first: Weighted Random Shuffling#535
Open
apolcyn wants to merge 5 commits intogrpc:masterfrom
Open
Conversation
easwars
reviewed
Jan 27, 2026
ejona86
approved these changes
Jan 27, 2026
ejona86
reviewed
Jan 27, 2026
easwars
approved these changes
Jan 28, 2026
dfawley
approved these changes
Jan 30, 2026
easwars
added a commit
to grpc/grpc-go
that referenced
this pull request
Jan 30, 2026
This PR implements the currently in-review gRFC A113: grpc/proposal#535. I've split the PR into logically separate commits to help with the review process. Summary of changes: - Commit 1: simplify the implementation of `groupLocalitiesByPriority` - Change the implementation to use newly added methods in the stdlib `maps` and `slices` package to significantly simplify the implementation (and get rid of an unnecessary test) - Commit 2: Remove code that handles localities and endpoints of weight 0 - Remove unnecessary checks for locality and endpoint weights of `0` in `cluster_resolver`. The xDS client already guarantees that these weights will never be set to `0`. - Commit 3: add the env var GRPC_EXPERIMENTAL_PF_WEIGHTED_SHUFFLING - Commit 4: Weight computation changes in cluster_resolver LB policy - This performs the weight normalization and fixed-point arithmetic specified in A113 - The change here is guarded by the above env var - Ended up duplicating the tests that verify the weight computation behavior. This will make it easier to delete the old tests when the env var is removed. - Commit 5: Fix a broken test in ring_hash due to the new weight computation - Commit 6: Weighted shuffling in pick_first - Contains the changes specified in A113 for the pick_first LB policy - Changes are guarded by the env var RELEASE NOTES: - pickfirst: Add support for weighted random shuffling of endpoints, as described in gRFC A113
markdroth
approved these changes
Feb 9, 2026
Member
markdroth
left a comment
There was a problem hiding this comment.
Approving, with two minor comments.
| each priority and endpoint weights within locality; the final weight provided to `pick_first` should be a | ||
| product of the two normalized weights (i.e. a logical AND of the two selection events). | ||
|
|
||
| The CDS LB policy currently calculates per-endpoint weight attributes. It will continue to do so however |
Member
There was a problem hiding this comment.
The second sentence in this paragraph is a run-on. It probably needs to be broken into two, with the second sentence starting with the word "however".
| This "fix" will not require any changes within Ring Hash LB itself. | ||
|
|
||
| We can continue to represent weights as integers if we represent their normalized values in | ||
| fixed point UQ1.31 format. Math as follows (citation due for @ejona): |
Member
There was a problem hiding this comment.
Can we fill in this citation before merging?
markdroth
approved these changes
Feb 9, 2026
Member
markdroth
left a comment
There was a problem hiding this comment.
Approving, with two minor comments.
eshitachandwani
pushed a commit
to eshitachandwani/grpc-go
that referenced
this pull request
Feb 11, 2026
This PR implements the currently in-review gRFC A113: grpc/proposal#535. I've split the PR into logically separate commits to help with the review process. Summary of changes: - Commit 1: simplify the implementation of `groupLocalitiesByPriority` - Change the implementation to use newly added methods in the stdlib `maps` and `slices` package to significantly simplify the implementation (and get rid of an unnecessary test) - Commit 2: Remove code that handles localities and endpoints of weight 0 - Remove unnecessary checks for locality and endpoint weights of `0` in `cluster_resolver`. The xDS client already guarantees that these weights will never be set to `0`. - Commit 3: add the env var GRPC_EXPERIMENTAL_PF_WEIGHTED_SHUFFLING - Commit 4: Weight computation changes in cluster_resolver LB policy - This performs the weight normalization and fixed-point arithmetic specified in A113 - The change here is guarded by the above env var - Ended up duplicating the tests that verify the weight computation behavior. This will make it easier to delete the old tests when the env var is removed. - Commit 5: Fix a broken test in ring_hash due to the new weight computation - Commit 6: Weighted shuffling in pick_first - Contains the changes specified in A113 for the pick_first LB policy - Changes are guarded by the env var RELEASE NOTES: - pickfirst: Add support for weighted random shuffling of endpoints, as described in gRFC A113
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.