Ruby on rails and a replicated MySQL instance -
[disclaimer: i'm wearing devops hat, isn't full-time hat. don't have ror hat, best.]
i have ror application runs in several data centres. mysql lets me replicate data dc's, 1 instance of mysql writeable. (yes, there techniques replicate master, don't believe ror maintains necessary contracts safely. maybe i'm wrong.)
most of time, ror reading mysql, faster if tell ror use local mysql instance except when needs write something.
or maybe i'm looking @ problem incorrectly , can tell mysql mean. (indeed, perhaps right thing set mysql proxy instance , tell it read/write splitting.)
one solution create 2 different connections same class, 1 connection connect writeable db, , other readable db.
keep original db connection class, create readable-only class, you'll have 2 different classes defined:
class example < activerecord::base end class readexample < activerecord::base establish_connection configurations['read_example'][rails.env] end
wherever want make read-only call, replace 'example' 'readexample'.
i haven't tested this, think should work. danger putting 'readable' class on call writes.
Comments
Post a Comment