“Reads -> slaves, writes -> master” plugin

Posted by Dr Nic on April 15, 2007

Another solution to multiple connections in Rails has been put together by the Revolution Health team.

Look at this sweet database.yml syntax:

dbs:

  database: master_db
  host: master-host

  read_only:
    database: slave_db
    host: slave-host

ActsAsReadonlyable adds support of multiple read-only slave databases to ActiveRecord models. When a model is marked with acts_as_readonlyable, some of AR finders are overridden to run against a slave DB. The supported finders are find, find_by_sql, count_by_sql, find_[all_]by_*, and reload.

README all about it.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. AkitaOnRails Mon, 16 Apr 2007 14:44:15 UTC

    Absolutely sweet, two solutions for a problem that started with a discussion not a week old. I was guessing that perhaps a big website as Revolution Health didn’t came by a similar problem than Twitter’s. You Magic Multi Connections and this ActsAsReadonlyable both goes by the same direction and they are fine. Yours expects an explicit conn proxy method - which I like. And Revolution’s approach is more transparent although we should be aware of any conflicts maybe with our own overwriting the finders and check out the logs to see if every finder is actually hitting the slaves. Anyhoo, congratulations for both authors for your creativity and quick response to the community.

  2. [...] “Reads -> slaves, writes -> master” plugin Looks like the Ruby community is stepping up to tackle the scale problem. I hope they keep this development up and don’t just say “we fixed it”. [via Dirk] [...]

  3. links for 2007-09-18 « Mike Does Tech Tue, 18 Sep 2007 02:36:11 UTC

    [...] Dr Nic » “Reads -> slaves, writes -> master” plugin (tags: rubyonrails database scaling) [...]

Comments