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

about the connection load balancing #99

Closed
1261385937 opened this issue Sep 18, 2020 · 2 comments
Closed

about the connection load balancing #99

1261385937 opened this issue Sep 18, 2020 · 2 comments

Comments

@1261385937
Copy link

hi ,
I found the load balancing of connections to slave is std::shuffle , this may be cause all connections to just one slave node if has a small number of slaves.
Actually, it happeds to me. I use sentinel mode , one master and two slaves. Master has 5 connections , slave 1 has 10 connections and slave 2 has no connections . slave 1 node cpu cost is high , but slave 2 node cpu is so free.

it is better if use round robin for valid slave nodes ?

@sewenew
Copy link
Owner

sewenew commented Sep 19, 2020

@1261385937 The current strategy, I.e. randomly pick one slave and only one, is based on the following reasons:

  • keep data consistency: since the synchronization from master is asynchronous, multiple slaves might different copies of data. If we use round robine way to get data from different slaves, the data inconsistencies problem might be worse, I.e. first call to get a key, return the value, second call returns nil, third call returns a value again.
  • avoid too many connections: if we use round robin way, we need to keep a connection pool for each slave. So there will be N * M * S connections (N is the number of client, M is the number of slaves and S is the size of the connection pool).
  • Normally, there’re multiple clients (on different hosts), and each client connects to a random slave. So there won’t be a load balance problem.

However, in your case, I think you only have a single client on a single host, so only one slave has connections. You can solve the problem by creating multiple Redis objects, and randomly pick one to send requests.

There was a plan to have customized strategy. However, it needs too many changes, so the priority of this feature is low. If there’s some progress on it, I’ll let you know.

Regards

@1261385937
Copy link
Author

thanks, i will take your suggest

@sewenew sewenew closed this as completed Sep 27, 2020
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

No branches or pull requests

2 participants