Skip to content

Conversation

@apolcyn
Copy link
Contributor

@apolcyn apolcyn commented Jan 27, 2026

No description provided.

also for Ring Hash
* Using fixed point Q31 format has predictable bounds on precision, and allows us to continue representing
weights as integers. Note our math assumes the sum of weights within a grouping does not exceed max uint32,
which is mandated in the XDS protocol.
Copy link
Member

Choose a reason for hiding this comment

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

Somewhere we should say we are preserving the "sum is a uint32" property for the internal weights (after the multiplication). That can be in the CDS section, or in this section. But we should call it out as a thing we are doing on purpose and desire. (It could also be used as an explanation for why we are using unsigned UQ1.31 instead of UQ32)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, done

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 Q1.31 format. Math as follows (citation due for @ejona):
Copy link
Member

Choose a reason for hiding this comment

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

If you're going to use this notation, then it is UQ1.31. Q1.31 is signed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks fixed


CDS LB policy and Pick First LB policy behavior changes will be guarded by `GRPC_EXPERIMENTAL_PF_WEIGHTED_SHUFFLING`.

Barring unexpected issues, this should be enabled by default.
Copy link
Member

Choose a reason for hiding this comment

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

"After testing"? (Although unit testing isn't enough...) Or "after the implementation is shown to be stable"? I feel like we've written something like that before, but I don't recall where.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

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
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.

5 participants