Reputation: 473
We have a Ruby on Rails 4.2.8 project that accesses a large PostgreSQL database. We are going to add a new server for connection pooling using PgBouncer.
Since PgBouncer will handle the db connection pooling, would we need to turn off Rails automatic connection pooling? We do not have anything configured in our database.yml, so I would think that the default (Pool) of 5 is being used.
Thank you
Upvotes: 3
Views: 3505
Reputation: 2915
TLDR; don't change anything
The pooling in rails is different than the pooling in PGBouncer. The rails connection pool is a group of connections available to any thread within that process, usually just 1. Each connection in your rails pool will have a connection to your postgres database, or PGBouncer if that's sitting in front of postgres. In a large rails app, you'll run multiple rails processes on every server and multiple servers behind a load balancer. Something like this:
Without PGBouncer, every connection to postgres creates a new postgres process. At scale you'll want to limit the number of postgres processes that run so you don't max out CPU and memory. PGBouncer pools connections from all of your rails pools across all processes and all servers, and efficiently switches between them.
Upvotes: 8