简体   繁体   中英

Disabling Connection Pooling in Rails to use PgBouncer

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.

  1. Does the addition of PgBouncer mean we should turn off Rails connection pooling?
  2. If so, how does that work, do we just set Pool to 0 in the database.yml?

Thank you

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM