Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rails] Connection Pool Timeout #48

Closed
hrdwdmrbl opened this issue Feb 27, 2013 · 0 comments
Closed

[Rails] Connection Pool Timeout #48

hrdwdmrbl opened this issue Feb 27, 2013 · 0 comments

Comments

@hrdwdmrbl
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant