Giter Site home page Giter Site logo

Comments (9)

jer0m avatar jer0m commented on August 18, 2024

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.

KensoDev avatar KensoDev commented on August 18, 2024

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.

nowthatsamatt avatar nowthatsamatt commented on August 18, 2024

Well KensoDev, you ever get something going on this? Running into the same spot.

from octopus.

KensoDev avatar KensoDev commented on August 18, 2024

@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.

nowthatsamatt avatar nowthatsamatt commented on August 18, 2024

We're using MySQL but this gave me something to think about - thank you!

from octopus.

KensoDev avatar KensoDev commented on August 18, 2024

@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.

sobrinho avatar sobrinho commented on August 18, 2024

I will do some research this week about how master/slaves databases (not applications) works in that situation.

from octopus.

dreyks avatar dreyks commented on August 18, 2024

Is there any advancement in this feature?

from octopus.

sobrinho avatar sobrinho commented on August 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.