6
votes

Is there a way to increase the connection timeout for ActiveRecord?

I keep getting this error when I have more than 25 threads with a pool size of 5.

(ActiveRecord::ConnectionTimeoutError) "could not obtain a database connection within 5 seconds (waited 5.000144774 seconds). The max pool size is currently 3; consider increasing it."

If there is not a way to increase the connection timeout, what is the best way to ensure a thread is using a connection as quick as possible?

2

2 Answers

5
votes

According to docs you should set the "checkout_timeout" option in your database configuration file.

checkout_timeout: number of seconds to block and wait for a connection before giving up and raising a timeout error (default 5 seconds).

3
votes

You can add

pool: 5

in your database.yml.

you can also set the checkout_timeout value, but I do not recomend it, because your application might take more seconds to answer it. If the error is throw when the system is under many requests, it is probably better to just give more possible simultaneous connections instead of making each request wait longer to finish.