teespring-labs/active_record_replica

Support for multiple slaves?

johnathanludwig opened this issue · 3 comments

The readme refers to the slave database in plural form in many places, but looking at the code and example it seems it only supports one slave.

Does this currently support multiple slaves?

There is a section in the readme about possible future enhancements, which is support for multiple slaves. Only wanted to add this feature if there is demand for it.

I will be happy to add the feature.

When supporting multiple slaves we have a few options:

  • Randomly select a slave instance on startup to balance load.
  • Use another algorithm to choose a slave on process startup, such as lowest ping time.
  • Or, name slaves and in the code explicitly select which slave to connect to for selected blocks of code.

Do you have a specific use case that we can address?

I would say a random selection to balance the load. The other two would be nice to have as options in the future.

On Thu, Nov 12, 2015 at 9:47 PM, Reid Morrison notifications@github.com
wrote:

There is a section in the readme about possible future enhancements, which is support for multiple slaves. Only wanted to add this feature if there is demand for it.
I will be happy to add the feature.
When supporting multiple slaves we have a few options:

  • Randomly select a slave instance on startup to balance load.
  • Use another algorithm to choose a slave on process startup, such as lowest ping time.
  • Or, name slaves and in the code explicitly select which slave to connect to for selected blocks of code.
    Do you have a specific use case that we can address?

    Reply to this email directly or view it on GitHub:
    #1 (comment)

I could build this behavior directly into active_record_slave, or we could do it in the database.yml as follows:

production:
  database: production
  username: username
  password: password
  encoding: utf8
  adapter:  mysql
  host:     master1
  pool:     50
  slave:
    database: production
    username: username
    password: password
    encoding: utf8
    adapter:  mysql
    host:     <%= %w(slave1 slave2 slave3).sample %>
    pool:     50