Rails Multi-DB Connection Pool Management Goodness
UPDATE: It seems another option has come up, I’ve found this acts_as_with_readonly plugin which hooks into AR so you can then have AR read from a pool of slaves. http://revolutiononrails.blogspot.com/
“““““““`
So i’m sitting here in a internet cafe, enjoying my vacationing on the French Riviera and saw the great news in my feedreader. Rails DB connection pooling at last!
Oh yes, it seems a solution has finally arrived for accessing multiple databases in Rails.
Dr. Nic has posted an article detailing it. It requires the magic_multi_connections gem and a few modifications to your environment.rb file. You can then specify clones to connect to and distribute load on the database backend.
The best part is its simplicity and transparency of it all. To read from a pool of databases it will essentially look something like this:
class PeopleController < ApplicationController
def index
@people = conn::Person.find(:all)
end
end
The magic is in the conn:: method which in the background selects a clone at random. Though I do think maybe in the future there will be a more intelligent form of load-balancing and database selection.
It is not limited to just reading off clones, you can set all writes to go to just the master, but reading from all database servers can be setup as well. You can also customize the setup to fit your environment, for example if you did table segmentation for users (A-E on database1, E-M on database2 etc).
.
Posted on April 14, 2007
Filed Under Analytics, Business, Daily Thoughts, Design, Productivity, Ranting, Ruby on Rails, Tech, Web
Related Posts:
-
Ajax on Rails and some practical SVN goodness
RFacebook Rails Plugin
Rails Cookbook - Fresh off the Press
The Ruby on Rails Triad
SugarStats.com launches private-beta of online diabetes management site
SugarStats.com Redesign and New Features Rollout
Comments
Leave a Reply
