-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add round-robin picker #16
Conversation
TCN-1912 Add round-robin picker
To make sure multiple replicas don't iterate connections in the same order (potentially resulting in thundering herd of concurrent requests to each backend), this should shuffle the order of connections before iterating. |
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.
Seems good. I think we should improve the shuffling, but I also have other concerns about using the global rand
. I have an idea in a branch I'll push and see what you think.
// TODO: when possible, it'd be good to test multiple connections to verify | ||
// that shuffling works and that we get round-robin behavior. |
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.
Would also be good to do some "white-box" testing: to actually look at the conns
slice of the resulting picker and verify it emits connections in actual round-robin sequence.
Doesn't look like there's a cleaner way to initialize an atomic wrapper.
Co-authored-by: John Chadwick <jchadwick@buf.build>
This was as simple as I could manage to make it. Hopefully close to what was in mind.
Per TCN-1912, it shuffles the connections whenever it gets a new list. Since we can't shuffle the Conns in place, I can't just use
rand.Shuffle
directly since it is doing an in-place Fisher-Yates shuffle. However, I believe this is still fine, as it should still yield a result where any permutation is equally likely.