Skip to content

kubernetes: replace hashring with compatible local pod selection - #4078

Open
crazy-max wants to merge 1 commit into
docker:masterfrom
crazy-max:remove-hashring
Open

crazy-max wants to merge 1 commit into
docker:masterfrom
crazy-max:remove-hashring

Conversation

@crazy-max

Copy link
Copy Markdown
Member

Replace the serialx/hashring dependency with a local implementation for sticky pod selection. Buildx only uses the library to construct an unweighted ring and perform one lookup, so a single scan avoids allocating and sorting the ring while preserving existing context-to-pod assignments and cache locality.

The implementation retains the original hash ordering, exact-match and wraparound behavior, and random-chooser fallback when the initial pod list is empty. Compatibility was checked against the previous library across 64,000 selections, with permanent regression tests covering representative assignments, pod removal, and fallback behavior.

@AkihiroSuda

Copy link
Copy Markdown
Collaborator

a single scan avoids allocating and sorting the ring

Do you have benchmark data?

@crazy-max

Copy link
Copy Markdown
Member Author

Yes, I compared the previous hashring implementation against the new scan, including ring construction on every call. Both use the same pod filtering and sorting code, with an in-memory pod list replacing the Kubernetes API request.

These are medians of six runs:

Pods Old ns/op New ns/op Old B/op New B/op Old allocs/op New allocs/op
1 1,924 1,188 1,656 656 31 16
3 3,064 1,693 2,216 736 47 20
10 7,441 3,179 5,824 1,040 97 29
30 19,289 6,450 17,953 1,616 208 50
100 52,754 17,097 47,778 4,400 568 122

The scan takes 38–68% less time in these measurements and allocates less at every pod count. Note that removing the dependency while preserving existing assignments is still the main benefit.

Select sticky pods with a single scan instead of constructing and sorting a
hash ring. Preserve the existing hash ordering, successor semantics, and
random-chooser fallback when the initial pod list is empty.

Remove the hashring dependency and add compatibility fixtures covering existing
assignments, exact matches, wraparound, and pod removal. Add regression coverage
for the fallback succeeding, finding no pods, or returning a list error.

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants