8

My website has a very heavy read traffic. A lot heavier than write traffic.

To improve the performance of my website I have thought of going with master/slave database configuration.

The octupus gem seems to provide what I want, but since my app is huge I can't go though a millions of source code line to change the query distribution(sending read query to slave server and write query to master server).

MySQL Proxy seems to be a great way to resolve this issue but since it is in alpha version I don't want to use it.

So my question is what is the best way to split read/write queries across master/slave server?

Is it possible to split read/write query without using any gems in rails?

4

2 回答 2

11

我刺出了 2 颗宝石,章鱼和马卡拉。我写了一篇比较这两个宝石的博客:https ://ypoonawala.wordpress.com/2015/11/15/octopus-vs-makara-read-write-adapters-for-activerecord-2/

在我看来,Makara 效果很好,弥补了 Octopus 的问题。

于 2015-11-22T07:51:08.213 回答
5

使用 octopus gem,您无需更改大部分代码即可将写入查询发送到主数据库服务器并将读取查询发送到从属数据库。

这是一个简单的配置文件,如此所述。

我过去试过这个,效果很好。对我来说唯一的问题是,当从属服务器关闭时,它不会像我在这里问的那样将查询“重定向”到主数据库服务器。

但是,如果要配置每个单独的查询目标,则需要一些工作。

我建议您开始映射您更频繁的查询以及那些需要更长时间才能响应的查询。了解这些查询后,您可以单独优化它们。这可能已经解决了部分问题。

如果在那之后您仍然需要主从复制,请使用 octopus gem 仅更改那些少数复杂查询的行为。

于 2015-04-14T13:33:13.183 回答