How to properly setup multiple databases?

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:
    https://gist.github.com/3807073. 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}”
end

  1. 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?

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

[1] https://github.com/rails/rails/pull/5872
[2] https://github.com/rails/rails/issues/7019

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs