Skip to content
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

Merged
merged 5 commits into from
Jun 7, 2023
Merged

Add round-robin picker #16

merged 5 commits into from
Jun 7, 2023

Conversation

jchadwick-buf
Copy link
Member

@jchadwick-buf jchadwick-buf commented Jun 7, 2023

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.

@jchadwick-buf jchadwick-buf requested a review from jhump June 7, 2023 20:47
@linear
Copy link

linear bot commented Jun 7, 2023

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.

Copy link
Member

@jhump jhump left a 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.

balancer/picker/roundrobin.go Outdated Show resolved Hide resolved
Comment on lines +29 to +30
// TODO: when possible, it'd be good to test multiple connections to verify
// that shuffling works and that we get round-robin behavior.
Copy link
Member

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.

balancer/picker/roundrobin.go Outdated Show resolved Hide resolved
jchadwick-buf and others added 3 commits June 7, 2023 19:04
Doesn't look like there's a cleaner way to initialize an atomic wrapper.
Co-authored-by: John Chadwick <jchadwick@buf.build>
@jchadwick-buf jchadwick-buf enabled auto-merge (squash) June 7, 2023 23:54
@jchadwick-buf jchadwick-buf merged commit 28af0ef into main Jun 7, 2023
@jchadwick-buf jchadwick-buf deleted the jchadwick/roundrobin branch June 7, 2023 23:56
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.

2 participants