We are working on a simple Rails 4 webapp, hosted by Heroku with the free plan.
Recently, we are experiencing some ActiveRecord::ConnectionTimeoutError
- on
In my experience these issues will come up on basic Heroku plans. There are a number of ways to mitigate the frequency without added cost. But you will never get to 0% occurrance with the basic/hobby stack.
Here's why in my experience.. until you hit 'premium-yanari' you wont get High Availability. You can get 99.95% expected uptime vs the free 99.5%. Doens't sound like much, but Heroku charges $150 extra for a reason (compared to the 'standard-yanari' plan).
After all the optimizations with connection pooling, reaping frequency, and forking, if your process cannot reach the database server you'll get a timeout. If this is the only cause, it will happen very infrequently, which may be your case. Only until I upgraded to 'premium-yanari' did this seemingly random timeout stop occurring.
I'm not suggestion you start paying $200/mo as a solution. You can get to near zero with a few suggestions below. Tuning concurrency, db connection, and experimenting with various options like timeouts take some trail and error - as there seems to be no plug-and-chug formula to give you a perfect combination for all these parameters.
1) Move to Unicorn to take more control of your processes and database connections. Here is a sample unicorn.rb file https://gist.github.com/blotto/8005531b9c94f3732240
2) Increase your timeouts ( currently 5 seconds ). See unicorn.rb :
timeout ENV['REQUEST_TIMEOUT'].to_i > 0 ? ENV['REQUEST_TIMEOUT'].to_i : 15
3) Be sure you're on the latest stable Rails 4.1.1. As 4.0.x did have some Postgres adaptor issues. See https://github.com/rails/rails/issues/12867