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

load balancing: add discovered server in a random position of the server list #565

Closed
matthiashanel opened this issue May 1, 2020 · 5 comments · Fixed by #566
Closed
Assignees
Labels
feature New feature request

Comments

@matthiashanel
Copy link
Contributor

Feature Request

Saw this through code inspection.
The connect list is shuffled.
New server are added to the end.
This makes server, the client learns about, less likely to be picked during a re-connect.

Use Case:

Any situation where we have 2 server running, then start a third, then kill one of the former server.
Clients are equally distributed between server (a,b)
We start server c.
Because server c gets added to the end of the list it will result in the client having one of these two lists:
a, b, c (current is a)
b, a, c (current is b)

if now we restart either a or b, all clients will connect to the other one, not c.

Proposed Change:

insert the new server at a random location in the list.

Who Benefits From The Change(s)?

This is useful to reduce thundering heard and better load balancing.

Alternative Approaches

@matthiashanel matthiashanel added the feature New feature request label May 1, 2020
@derekcollison
Copy link
Member

I agree with this. We should just reshuffle?

@ColinSullivan1
Copy link
Member

Reshuffle imo, but remove the last connected server first. ;)

@matthiashanel
Copy link
Contributor Author

@derekcollison it would be enough to insert at a random location.
(probably correcting for what the current server)

@ColinSullivan1
Copy link
Member

ColinSullivan1 commented May 1, 2020

Shuffle, then add last connected at the end imo. Alternatively, shuffle, then insert randomly anywhere except the front of the list.

@derekcollison
Copy link
Member

We could get elaborate for sure.. ;)

End result should be backup servers always shuffled when added to (don't think required for removal) with current connected at the end of the list.

kozlovic added a commit to nats-io/nats.c that referenced this issue May 6, 2020
If randomize is allowed, discovered URLs will be randomly added
to the pool of urls instead of always be appended.

See nats-io/nats.go#565

Signed-off-by: Ivan Kozlovic <[email protected]>
kozlovic added a commit that referenced this issue May 6, 2020
After adding discovered URLs from the INFO, reshuffle the pool
if option allows

Resolves #565

Signed-off-by: Ivan Kozlovic <[email protected]>
kozlovic added a commit to nats-io/nats.c that referenced this issue May 6, 2020
If randomize is allowed, discovered URLs will be randomly added
to the pool of urls instead of always be appended.

See nats-io/nats.go#565

Signed-off-by: Ivan Kozlovic <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants