简体   繁体   中英

Rails ActiveRecord w/ MySQL Hangs Once Connection Pool Limit is Reached

Unless specified, ActiveRecord fires up 4 default connections.

I've noticed if I reload a simple page, which makes at least one ActiveRecord call, 4 times every thing functions normal. However, on the fifth time, it hangs for almost 5 seconds. So, every 5th page load it hangs for 5 seconds.

I upped the default connection pool in my adapter to 8 and now it hangs every 9th page request. It seems like it doesn't reuse connections but instead kills them and regenerates them once the pool limit is reached.

I'm not actually using ActiveRecord with entire Rails stack.

Is there a magical ActiveRecord connection flag which prevents this from happening? Or, is there something else going wrong?

Hot damn that was easy...

ActiveRecord::Base.clear_active_connections!

http://coderrr.wordpress.com/2009/01/12/rails-22-activerecord-connection-cleanup/

Sure wish this was something you could configure so you don't have to call it every time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM