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

Randomize brokers to connect to from the connection seed #631

Closed
fjuan opened this issue Jan 14, 2020 · 3 comments · Fixed by #632
Closed

Randomize brokers to connect to from the connection seed #631

fjuan opened this issue Jan 14, 2020 · 3 comments · Fixed by #632

Comments

@fjuan
Copy link

fjuan commented Jan 14, 2020

In order to better spread connection load towards brokers, clients could randomize the one broker selected to initiate the connection from the seed brokers list.

const [seedHost, seedPort] = brokers[index++ % size].split(':')

The randomization mechanism should be aware of the possiblity that the selected broker is not available. A suggestion could be to change the default index value at

const size = brokers.length
let index = 0

Maybe something like

let index = Math.floor(Math.random() * size)
@fjuan
Copy link
Author

fjuan commented Jan 14, 2020

Another implementation idea would be to shuffle the list of brokers right after reading it and keep the current connectionBuilder.js as is. Suggestion from @matthiasfeist

@Nevon
Copy link
Collaborator

Nevon commented Jan 14, 2020

I'm of two minds on this.

On the one hand, this is probably the behavior you want in 90% of cases, so from that perspective it makes sense for us to handle it internally.

On the other hand, there may be situations where you actually want to prefer connecting to a certain broker, which would become impossible to do if we force a random order. If we don't do this in the client, it's still easily implementable in userland code by just shuffling the list before handing it to the client.

Of course there's always the option of shuffling the list by default and then introducing a way to disable that later if/when it becomes needed.

Nevon added a commit that referenced this issue Jan 14, 2020
Allows spreading the initial connection load towards the brokers, we
shuffle the order of the seed brokers. They are still iterated through
in the same way when a connection fails, just not necessarily in the
same order they were originally specified.

Fixes #631
@tulios
Copy link
Owner

tulios commented Jan 14, 2020

Out on pre-release 1.12.0-beta.21

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 a pull request may close this issue.

3 participants