-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Cluster: problem when using Slaves for READ operations #170
Comments
Hi @Adrien-P, |
Hi @luin , thanks for the answer. |
Yes, I agree with you. I'd like to deprecate the |
Yes I agree the readOnly option is not the best name for this. Because eventually, you can make write operations with this option too. I guess that's directly inspired from the |
For customize lua function, how can we know read or write?, maybe we need another option when we define the lua function? |
hey @luin, any estimate on when v2 will be out? Anything we can do to speed it up? |
@shaharmor v2 will be out within two months. |
@luin any update on this? we could really use this for scaling our cluster. |
It's the top priority in my list, however I still haven't got time to implement it. A project of my company will switch to redis cluster soon (we have 60GB redis data) and we rely on ioredis heavily, so I'll definitely have this feature implemented before our migration. |
Not sure if this has been though about or not, but we would very much like if it would be possible to send all reads only to slaves, and not mix with master (When there are slaves available obviously). |
Yes, I've considered this case and there will be an option for this. |
The new option scaleReads is used to specify where to send the reads. Add two new events: 1. "+node": a new node is discovered. 2. "-node": a node is disconnected. BREAKING CHANGE: 1. Cluster#masterNodes and Cluster#nodes is removed. Use Cluster#nodes('masters') and Cluster#nodes('all') instead. 2. Cluster#to() is removed. Use Promise.all(Cluster#nodes().map(function (node) {})) instead. Closes #170.
Closing in favour of #247. |
I'm using Redis in Cluster mode with ioredis.
I discovered the
{ readOnly: true }
option which looks amazing.However, I've got some new MOVED errors since using this option.
It is only happening on write operations (
del
,hincrby
, etc.).I looked at the code and this piece of code (in cluster.js) attracted my attention:
My guess: when the option readOnly is activated, it selects randomly one of the nodes that is reponsible of the targetSlot. In a setup where you've got a Slave for each Master, the selection is made between two nodes (one Master and its Slave). It means that the Read operations are randomly distributed between these two nodes, which is the objective (even though I originally thought it would only go on Slave nodes).
However, it seems that the same process is applied for Write operations. It creates an issue because if the Slave node is selected for this operation, it will return a MOVED error. Eventually, with a few retries there is a good chance that the Master node will be picked by the random selector. So the operation has a good chance of succeeding. However, it looks very inefficient and with a lot of operations you'd get some operations actually failing.
Please let me know if it's a bug or if I'm not using the library properly
The text was updated successfully, but these errors were encountered: