Lighty+Mongrel: Limiting persistent db connections?

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



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. :slight_smile:

Zed A. Shaw

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


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 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