[Rails] Connection Pool Timeout #48

hrdwdmrbl opened this Issue Feb 27, 2013 · 0 comments


None yet
1 participant

I was having an issue where I was trying to perform too many long running DB connections in parallel. Rails suggested I increase my connection pool size, but I was afraid of having too many connections to mySQL per web worker process.

I realized my error was that I was simply using too many of the available connections, so I wanted to make sure I never exceeded the available pool. My solution was to use something like

:in_threads => [User.all.lenght, ActiveRecord::Base.connection_pool.instance_eval { @size }].min

This will use the number of connections equal to the number of records, OR the connection pool size, whichever is smaller.

@hrdwdmrbl hrdwdmrbl closed this Feb 27, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment