-
Notifications
You must be signed in to change notification settings - Fork 505
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
Suggested way to handle read latency? #68
Comments
Did you try this: Octopus.using(:master) do You force the queries to be executed on your master. Useful to avoid replication latency in certain cases. |
I don't want to foce EVERYTHING to the master, that's missing the point of replication. Now, if there's a 3 second read latency, I will not see my review which will result in me thinking it's a bug (which it is) What I am trying to think about is a dirty flag, when you write something to the database, you will read from master for the next 30 seconds. The problem is doing it across servers on a load balancer without a sticky session. |
Well KensoDev, you ever get something going on this? Running into the same spot. |
@nowthatsamatt yeah, actually I did. first, in my app, only logged in users can write to the database, never logged out users. When there's a write to the database, I fire an even using I save it to redis and I force to master for that user for 5 minutes. |
We're using MySQL but this gave me something to think about - thank you! |
@nowthatsamatt We are using mySql as well, I am only using Redis as a faster data layer, and it's really a key-value need.
|
I will do some research this week about how master/slaves databases (not applications) works in that situation. |
Is there any advancement in this feature? |
I recently did a research about that and there is multiple ways to solve that. If you need to handle the delay only for the current user, you could use redis to store the last write like And using a around filter you could use a threshold like this: around_filter :handle_master_slave
def handle_master_slave
last_write = Time.parse(Redis.get("user:#{user.id}:last_write"))
threshold = 5.minutes # Tune to an appropriate threshold
if Time.current + threshold < last_write
Octopus.using(:master, &block)
else
Octopus.using(:slave, &block)
end
end There is a lot of other options like do that only for specific tables, objects, all users and etc. You must analyse your case to chose the appropriated solution. I'm planning to write a wiki page about that ASAP. |
Hey,
Using the gem in Amazon RDS.
When Amazon RDS sets up a read slave, there are times when you have 1 minute of replication latency.
Even though 1 minute is a rare case, 10 seconds latencies happen a few times a day.
From looking and the source code, this is obviously not handles, so I am thinking about implementing a
Dirty
kind of flag, so when the flag is true, you also read from the master.Opinions? Advice?
The text was updated successfully, but these errors were encountered: