Rails ActiveRecord w / MySQL freezes after reaching connection pool limit

If not specified, ActiveRecord starts 4 connections by default.

I noticed that if I reload a simple page that makes at least one call to ActiveRecord, 4 times each thing works fine. However, for the fifth time, it hangs for almost 5 seconds. Thus, every 5th page load freezes for 5 seconds.

I increased the default connection pool in my adapter to 8 and now it hangs every 9th page request. It does not seem to reuse connections, but instead kills them and restores them after reaching the pool limit.

I actually do not use ActiveRecord with the Rails stack.

Is there a magic ActiveRecord connection flag that prevents this? Or is there something else wrong?

+4
source share
1 answer

Damn it was easy ...

ActiveRecord :: Base.clear_active_connections!

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

Of course, that was something you could configure, so you don't need to call it every time.

+2
source

All Articles