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?
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With