Links
Seamless Database Pool
Categories
Seamless Database Pool
Seamless Database Pool provides a simple way in which to add support for a master/slave database cluster to ActiveRecord to allow massive scalability and automatic failover. The guiding design principle behind this code is to make it absolutely trivial to add to an existing, complex application. That way when you have a big, nasty application which needs to scale the database you won’t have to stop all feature development just to refactor your database connection code. Let’s face it, when the database is having scaling problems, you are in for a world of hurt and the faster you can fix the problem the better.
This code is available as both a Rails plugin and a gem so it will work with any ActiveRecord application.
In a master/slave cluster you have one master database server which uses replication to feed all changes to one or more slave databases which are set up to only handle reads. Since most applications put most of the load on the server with reads, this setup can scale out an application quite well. You’ll need to work with your database of choice to get replication set up. This plugin has an connection adapter which will handle proxying database requests to the right server.
You can convert a standard Rails application (i.e. one that follows the scaffold conventions) to use a database cluster with three simple steps:
- Set up the database cluster (OK maybe this one isn’t simple)
- Update database.yml settings to point to the servers in the cluster
- Add this code to ApplicationController:
include SeamlessDatabasePool::ControllerFilter use_database_pool :all => :persistent, [:create, :update, :destroy] => :master
If needed you can control how the connection pool is utilized by wrapping your code in some simple blocks.
One of the other main advantages of using any sort of cluster is that one node can fail without bringing down your application. This plugin automatically handles failing over dead database connections in the read pool. That is if it tries to use a read connection and it is found to be inactive, the connector will try to reconnect. If that fails, it will try another connection in the read pool. After thirty seconds it will try to reconnect the dead connection again. One limitation on failover is that a server with an unreachable IP can’t failover on startup. If you have a server completely die and it can’t be restarted, you should update the pool configuration immediately to remove that entry.
Vitals
| Home | http://seamlessdbpool.rubyforge.org/ |
|---|---|
| Repository | http://seamlessdbpool.rubyforge.org/svn/tags/stable |
| License | Rails' (MIT) |
| Tags |
database performance scaling
|
| Rating | (16 votes) |
| Owner | Brian Durand |
| Created | 12 May 2008 |
Comments
-
followed the instructions, but got following: (in C:/build/MyPeeradise) rake aborted! [Fiveruns] Could not install instrumentation: Could not determine database adapter [C:/build/MyPeera....
-
You Rock Brian! You should start throwing in BadA%%Mofo in your plugin namespaces
-
Version 1.0.2 is now compatible with Rails 2.3 and with plugins that alias ActiveRecord connection methods.

