Conversation
A request can carry a uint8 value at SpreadCtxKey in its context. The picker then uses that spread instead of the spread from the balancer config. This lets a caller widen the candidate set for one key, for example to spread a measured-hot key across more backends, without a change to the global spread. Also align the not-enough-members fallback with its comment: - A spread that exceeds the count of ready members now uses all ready members. Before, the pick collapsed to a single member. - A pick against an empty ring queues the RPC. The clamp needs an explicit guard for this case, because FindN(key, 0) returns an empty result and no error.
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.
Problem
Spread is a single value in the balancer config, so every key gets the same number of candidate backends. A caller that detects a hot key cannot spread only that key across more backends. Raising the global spread dilutes cache locality for every key to protect a few.
Change
A request can carry a
uint8value atSpreadCtxKeyin its context. The picker then uses that spread instead of the spread from the balancer config. The picker ignores a value of zero or of any other type.Also, this aligns the not-enough-members fallback with its comment:
FindN(key, 0)returns an empty result and no error.Tests
Four new tests: the override picks as the equivalent config spread would, a zero override uses the config spread, a spread above the member count uses all members, and a pick against an empty ring queues instead of panicking. The empty-ring test failed with a panic before the guard. The suite passes with
-race.