Ruby on Rails Sunday, September 30, 2012

I've setup my application to connect to multiple databases, but am running into a few issues in production.  I also have a few questions.

First, I'm using rails 3-2-stable, because I was running in to a prepared statement bug, which is only fixed in this branch [1].  I'm not up for using master at this time, unless I absolutely need to.

Second, the pool size for the default and non-default database is 1, this is because I'm using unicorn.  Also, because establish_connection on multiple databases does not use the pool size [2].

The issue:

I have 4 unicorn workers.  After I start the app and rapidly refresh on a few pages, the default database sees 4 connections.  The non-default database sees only 1.  And for the lifetime of the app, the non-default database only sees one connection. I also think this is slowing down the website.

1) What would cause the application to create only one connection for the non-default database, provided I have 4 workers?  When I create a sample app on my local machine that uses the same configs with different code, I actually get 4 connections for both.  See my unicorn file here:  All my non-default database models inherit from something that looks like:

class OtherDb < ActiveRecord::Base
  self.abstract_class = true
  establish_connection "other_#{Rails.env}"

2) What's the proper way to setup a unicorn.rb file for multiple databases with `preload_app true`, since I have establish_connection in the OtherDb model and need to establish_connection to the default in the after_fork?

3) Should I be looking into a different rack web server?  My queries are sub 500ms.


You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to
To unsubscribe from this group, send email to
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment