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 Mongrel? Joe -- Posted via http://www.ruby-forum.com/.
Zed Shaw
2006-Mar-17 05:47 UTC
[Rails] Lighty+Mongrel: Limiting persistent db connections?
Joe, Each mongrel you run takes a -n setting (-P on win32 though) that sets the number of processor threads. The way ActiveRecord works is that you get one DB connection for each thread using AR. Since the default is 20 processor 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 there''s one DB connection for each Mongrel. Still, it would better if AR just had a real LRU connection pool. :-) Zed A. Shaw http://www.zedshaw.com/ On 3/16/06 3:28 PM, "Joe" <joe@yahoo.com> wrote:> 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 > Mongrel? > > Joe
Ah, thanks. I decreased -n and that seems to have improved the situation. Is there any advantage in setting -n to greater than 1 when used with Rails? Joe -- Posted via http://www.ruby-forum.com/.
Zed Shaw
2006-Mar-17 13:57 UTC
[Rails] Re: Lighty+Mongrel: Limiting persistent db connections?
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 mongrel 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 over the socket queue and things start to get slower. 20 was about the right setting, but YMMV. Zed On 3/17/06 5:55 AM, "Joe" <joe@yahoo.com> wrote:> Ah, thanks. I decreased -n and that seems to have improved the > situation. > > Is there any advantage in setting -n to greater than 1 when used with > Rails? > > Joe