Upgrade to Pro — share decks privately, control downloads, hide ads and more …

R/W Splitting in Rails

Kohei Suzuki
September 19, 2014

R/W Splitting in Rails

Kohei Suzuki

September 19, 2014
Tweet

More Decks by Kohei Suzuki

Other Decks in Programming

Transcript

  1. 3BJMTBOENVMUJQMF%#T 3BJMTTVQQPSUTUPFTUBCMJTIDPOOFDUJPOTUPEJ⒎FSFOU EBUBCBTFTGPSFBDINPEFMT class BlogBase < ActiveRecord::Base self.abstract_class = true

    establish_connection :production_blog end ! class Article < BlogBase; end class Category < BlogBase; end ! class Comment < ActiveRecord::Base establish_connection :production_comment end
  2. $POpHVSBUJPO EBUBCBTFZNM production_blog_master: adapter: mysql2 database: blog username: blog_writable host:

    db-blog-master ! production_blog_slave: adapter: mysql2 database: blog username: blog_readonly host: db-blog-slave
  3. $POpHVSBUJPO .PEFMT class Article < ActiveRecord::Base use_switch_point :blog end !

    class Category < ActiveRecord::Base use_switch_point :blog end ! class Comment < ActiveRecord::Base use_switch_point :comment end