Rails & pg setup question

Поиск
Список
Период
Сортировка
Искать

Rails & pg setup question

От:
Scott Ribe <scott_ribe@elevated-dev.com>
Дата:
What I'm trying to determine is: should I plan on using pgbouncer?

With Rails & Passenger, do the app server processes take and hold connections to the db? Or take & release with queries/connections?

This is not a scalability question; given the traffic the site will have I only need a small handful of connections. It's a latency question, I don't want to be starting up new pg processes excessively.

(Yes, I thought about asking on the RoR list, since it's really a question about RoR behaviors, but on the other hand it involves pg optimization & best practice, which is, ahem, different than with MySQL.)

-- 
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




Re: Rails & pg setup question

От:
"Joshua D. Drake" <jd@commandprompt.com>
Дата:

On 02/25/2012 08:13 AM, Scott Ribe wrote:
>
> What I'm trying to determine is: should I plan on using pgbouncer?
>
> With Rails&  Passenger, do the app server processes take and hold connections to the db? Or take&  release with queries/connections?
>
> This is not a scalability question; given the traffic the site will have I only need a small handful of connections. It's a latency question, I don't want to be starting up new pg processes excessively.
>
> (Yes, I thought about asking on the RoR list, since it's really a question about RoR behaviors, but on the other hand it involves pg optimization&  best practice, which is, ahem, different than with MySQL.)
>

Alright I did a quick google and passenger appears to be essentially 
mod_rails, which means you are going to generate a connection for every 
httpd process you have (unless something has changed that I don't know 
about).

So on the one hand it is good because your connections will be 
persistent, on another hand it is bad because you will open connections 
even if you aren't using the database. That said, it is a rails app so 
it is likely you are using the database no matter what.

Where pgbouncer might come in handy here, is that it can open more 
connections than you have httpd processes, and thus you will reduce the 
fork cost of the new process just because someone hits the website.

JD

-- 
Command Prompt, Inc. - http://www.commandprompt.com/
PostgreSQL Support, Training, Professional Services and Development
The PostgreSQL Conference - http://www.postgresqlconference.org/
@cmdpromptinc - @postgresconf - 509-416-6579

Re: Rails & pg setup question

От:
Daniel Podlejski <underley@ciemnogrod.eu>
Дата:
"Joshua D. Drake" :

>  Where pgbouncer might come in handy here, is that it can open more 
>  connections than you have httpd processes, and thus you will reduce
>  the 
>  fork cost of the new process just because someone hits the website.

Unfortunatelly, ActiveRecords (Rails ORM) >= 3.1 is broken by design:
https://github.com/rails/rails/issues/1627

-- 
Daniel Podlejski
FAQ