Rails: How to split write/read query across master/slave database

橙三吉。 提交于 2019-11-28 12:15:31
Mauricio Moraes

With octopus gem, you don't have to change much of your code to make write queries go to the master db server and read queries go to the slaves.

It's a simple configuration file, as stated here.

I've tried this in the past and It worked quite well. The only problem for me is that when the slave is down, it doesn't "redirect" the queries to the master db server, as I asked here.

But, if you want to configure each individual query destination, it will take some work.

I would suggest you to start mapping your more frequent queries and those that are taking longer to respond. Knowing those queries, you can optimize them individually. This may already solve part of the problem.

If you still need master-slave replication after that, use the octopus gem to change the behaviour only those few complicated queries.

I spiked out 2 gems, Octopus and Makara. I have written a blog comparing these 2 gems : https://ypoonawala.wordpress.com/2015/11/15/octopus-vs-makara-read-write-adapters-for-activerecord-2/

In my opinion, Makara works well and makes up for the issues with Octopus.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!