On Mar 15, 4:56 pm, Andrew Selder <[email protected]> wrote: > Hi all, > > I currently am part of a team writing an app and I'm running into an > issue with connection pools. > > Quick infrastructure overview: Rails 2.2.2, Ruby 1.8.7p72, Apache/ > Mongrel, mongrel running single threaded. Due to legacy schema, the > mongrels are making connections to a couple of different DB. > > We currently are running about 28 mongrels, and obviously with a > default 5 connections/per mongrel, we're getting 140 connections to > the db. This seems kind of wasteful, especially as we scale larger. > > So the first thing I tried is setting the pool size to 1. I figured > since only one request is being processed at a time, there's only a > need for one db connection. However, this cause the app to start > spewing 'could not obtain db connection' errors. > > So I bumped the pool size up to 2, and things seem to be OK, however > when I go into mysql and show processlist, it looks like there are 4 > or 5 connections open. > > Basically, I realize that there the connection pool is necessary to > support multithreading, but is there any way to pare things down to > one connection per mongrel like the old day, when we aren't using the > multithreading? >
You can set the connection pool size to 1, but if you do that you need to be careful not to leak connections. During the normal request/ response cycle this is all handled for you but at app load times you will have to be careful. Stuff like class MyControllerClass < ActionController::Base SOME_CONSTANT = People.find :all end (contrived example but you get the point) will leak a connection because a connection will be used to execute the query but it won't be returned to the pool. You can clear out connections with ActiveRecord::Base.clear_active_connections! Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

