From: "Artūras Šlajus" Date: 2009-09-10T06:43:22+09:00 Subject: Re: EventMachine.defer and ActiveRecord connection pool? Chuck Remes wrote: > On Sep 9, 2009, at 4:14 PM, Artūras Šlajus wrote: > >> Nop, it's 1 second for testing. It happens even if you set it to 1 >> minute. Loads of time to clean up and still... >> > > Hmm, that is curious. Then here's another guess... > > I haven't used rails in a long time, but I recall that AR required a > call to verify_connections! or something crazy when running with > threads. Tried this with no luck :) Thou it gave me some idea for googling... > This is because each call opens its own connection to the > database but there is (or was) no automatic close. So it could be that > your threaded calls are opening up db connections and never closing > them. You need to figure out how to close the connection or get AR to > figure out that the others are stale or should be garbage collected. It seems that ActiveRecord::Base.clear_reloadable_connections! in: EventMachine.defer( proc do SingletonBlock.started(name) LOGGER.block(name) { operation.call } end, proc do LOGGER.block("#{name} CALLBACK") { callback.call } if callback SingletonBlock.finished(name) ActiveRecord::Base.clear_reloadable_connections! end ) actually helped :) (http://coderrr.wordpress.com/2009/01/12/rails-22-activerecord-connection-cleanup/) Thanks for ideas and help! ;) -- Posted via http://www.ruby-forum.com/.