0

我有一个小型 Rails 应用程序,我部署在 heroku 的免费层上,只有一个 API,没有用于创建书籍、返回书籍类型和从数据库中删除所有书籍的视图。它看起来有点像这样:

APOST request to site.herokuapp.com/add_book?name=harrypotter&genre=fantasy加了一本书。

AGET request to site.herokuapp.com/find_book?name=harrypotter返回流派。

一个POST request to site.herokuapp.com/reset clears the database of all books

现在我已经在一台服务器上工作了,我想在三台服务器上复制它,每台服务器都有一个唯一的 URL,这样我就可以将我的调用发送到 3 台服务器中的任何一台,并让它们的所有数据库都包含相同的 Book 条目。

例如,如果我发送一个

POST request to site1.herokuapp.com/add_book?name=harrypotter&genre=fantasy

然后发送一个

POST request to site2.herokuapp.com/add_book?name=littlewomen&genre=fiction

我可以发一个

GET request to site3.herokuapp.com/find_book?name=littlewomen.

但是,如果我向服务器发送重置调用,它不会重置其他服务器。

我发现了两个名为OctopusData Fabric的 gem,但看起来它们在同一台服务器上的数据库之间复制,而不是在不同的服务器上。另外,由于我要调用三个不同的站点,这些 gem 会起作用吗?

在 Rails 中进行这种类型的数据库/服务器复制的最佳方法是什么?

4

1 回答 1

0

Not sure if I quite understand your complete use case. Is it that you simply want to distribute reads/writes across the different databases for different API calls ?

If it is a small application why don't you have all 3 applications on site 1, site 2 and site 3 connect to the same database instance ?

Following options:

  1. Master Slave Replication

    In your case you would have 1 master db and 2 slave db. Data will be read and written to the master db but will be replicated to the slaves. You can then configure your rails application to do reads across selected databases.

    You can use Octopus to distribute writes/reads between slaves and master.

    When using replication, all writes queries will be sent to master, and read queries to slaves.

  2. MySQL Cluster

    I have not used MySQL cluster yet but should be using it soon. If your requirement is to distribute reads/writes across all the databases while having the data remain consistent across all nodes MySQL cluster looks like a good candidate. The data is distributed across a pool of data nodes. Every MySql server has access to all the data nodes and as result when a server within the cluster changes data example by inserting rows, this new data is immediately accessible and seen by the other MySql servers in the cluster.

    See more here MySql Cluster

于 2013-02-09T22:29:57.847 回答