Forum: Ruby on Rails Lighty+Mongrel: Limiting persistent db connections?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Joe (Guest)
on 2006-03-16 22:28
I'm not sure if it's due to setting up multiple mongrel servers and
proxying them with lighty, but something is keeping postgres connections
around. I only have a couple Rails apps running on a new server, with
not a whole lot of traffic, yet today I actually maxed out my connection
limit of 100 for postgres. How do I turn off persistent connections in

Zed S. (Guest)
on 2006-03-17 07:48
(Received via mailing list)

Each mongrel you run takes a -n setting (-P on win32 though) that sets
number of processor threads.  The way ActiveRecord works is that you get
DB connection for each thread using AR.  Since the default is 20
threads then you'll get 20 DB connections per mongrel setup.

The next release will have an option to turn this off for AR so that
one DB connection for each Mongrel.

Still, it would better if AR just had a real LRU connection pool.  :-)

Zed A. Shaw
Joe (Guest)
on 2006-03-17 12:55
Ah, thanks. I decreased -n and that seems to have improved the

Is there any advantage in setting -n to greater than 1 when used with

Zed S. (Guest)
on 2006-03-17 16:00
(Received via mailing list)
Yes, even though Rails runs in a synchronized block, the entire rest of
Mongrel tries to be thread safe.  So, if you want to be able to have
deal with more than one connection at a time then keep it above 1.

The catch is that if you increase it too much then the threads fight
the socket queue and things start to get slower.  20 was about the right
setting, but YMMV.

This topic is locked and can not be replied to.