The goal of this spike is to determine the behavior of rails replication and sharding solutions, specifically when selecting against associated records. We would like to see reads distributed across slaves where not instructed to do otherwise. Like so in the Octopus api:
# contrived example that actually doesn't work in octopus 0.8.2
irb(main):002:0> Artist.first.albums.count
[Shard: slave1] Artist Load (1.3ms) SELECT `artists`.* FROM `artists` LIMIT 1
[Shard: slave2] (1.1ms) SELECT COUNT(*) FROM `albums` WHERE `albums`.`artist_id` = 1
=> 4
- Fails to use shard on queries involving relations
- Querues the slave for all queries when forced with a block
- Raises when the slave is gracefully stopped
- Raises when the slave is down before query is made
- Raises when the mysql service is stopped or the slave is removed from the replica set
- Breaks rake db:reset (not a big deal, but I suspect others)
- With slave groups the situation gets worse with no reads to slaves by default
- Appears to support ActiveRecord versions 3 and 4
The closest octopus gets is directly selecting a slave with the using
method:
irb(main):002:0> Octopus.using(:slave1) { Artist.first.albums.count }
[Shard: slave1] Artist Load (1.3ms) SELECT `artists`.* FROM `artists` LIMIT 1
[Shard: slave1] (1.1ms) SELECT COUNT(*) FROM `albums` WHERE `albums`.`artist_id` = 1
=> 4
- Only supports replication solutions
- Has select-able 'sticky' behavior ensuring a single slave in use per session
- Timed blacklisting of servers upon outage
- Adjustable Error handler to customize blacklisting behavior
- Configuration is sensitive to things that seemingly shouldn't matter (port setting in slave definition crashes the things)
- Generally performs as described and is just thin enough to do the job well
- Appears to support ActiveRecord versions 3 and 4
- Breaks db: related rake tasks (and more) with multiple sets of credentials
- Crashes on slave outages or read errors
- More support for shards
- Also a thin layer, but more migration help for shards
- instructure/switchman - Code is a bit of a mess and the README warns of wip
- drecom/activerecord-turntable