Comments (9)
Did you try this:
Octopus.using(:master) do
// Your queries
end
You force the queries to be executed on your master. Useful to avoid replication latency in certain cases.
from octopus.
I don't want to foce EVERYTHING to the master, that's missing the point of replication.
the problem is that let's say I write a review, when I refresh I expect to see it on the page right?
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.
from octopus.
Well KensoDev, you ever get something going on this? Running into the same spot.
from octopus.
@nowthatsamatt yeah, actually I did.
I did not get a chance to open source it yet, but here's the gist of things
first, in my app, only logged in users can write to the database, never logged out users.
So, in an around_filer, I inject the current_user
into Octopus
.
When there's a write to the database, I fire an even using ActiveSupport::Notifications
with the user that wrote to the database.
I save it to redis and I force to master for that user for 5 minutes.
from octopus.
We're using MySQL but this gave me something to think about - thank you!
from octopus.
@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.
"user:#{user_id}:last_write" => DateTime.now
from octopus.
I will do some research this week about how master/slaves databases (not applications) works in that situation.
from octopus.
Is there any advancement in this feature?
from octopus.
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 "user:#{user.id}:last_write" => Time.current
(as @KensoDev suggested).
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.
from octopus.
Related Issues (20)
- Octopus 0.10.2 / Rails 5.1.5 / Sidekiq workers eventually run out of memory and freeze
- Not able to access the wiki page HOT 4
- Config file setting of wiki is outdated? HOT 1
- could not obtain a database connection within 5.000 seconds HOT 2
- Rails 6 migration / compatibility HOT 3
- How does the ActiveRecord connection pool interact with Octopus? HOT 4
- Rails 6 release HOT 6
- Octopus error at startup with Rails 6: `alias_method': undefined method `any?' for class `ActiveRecord::Associations::CollectionAssociation' (NameError) HOT 7
- Update methods sent to read-only database with identity_cache gem
- Sidekiq job random failures due to proxy_config is nil
- octopus for ruby project HOT 1
- Delayed Job + Octopus 0.10.2 issues on Rails 5.2 (undefined method `any?' for nil:NilClass) HOT 2
- ActiveRecord 5.2 StatementCache Pins Queries to Shards
- Octopus is already running
- octopus 0.6.1 make rake unit test failling.. HOT 1
- Would sponsorship help? HOT 2
- I can't able to use gem 'ar-octopus' in rails 6.0.3 HOT 2
- Octopus doesn't work with Rails' schema cache HOT 1
- New Maintainer HOT 4
- Preventing Duplicate Migrations on the Same Shard for Rails > 5.2 and ar-octopus (0.10.2) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from octopus.