actblue/abagnale — pull request #14 by decklin (2014-11-01 16:55:42+00:00)
Title: Use the AR connection pool manager middleware

So after deploying abagnale to playpens I found that performance was still mysteriously bad, and latency followed a pattern:

https://gist.github.com/decklin/42efb4805a92a3f71765

I looked at the default ActiveRecord connection pool settings and, surprise, there's a timeout of 5 seconds and a pool of 5 connections. The app doesn't close connections explictly, so every 5 connections, the next request sleeps (5 seconds is long enough for the existing connections to time out).

ActiveRecord includes a middleware which will close the connection automatically after each request, and AFAIK Rails includes it in the stack by default, but in Sinatra you have to `use` it yourself.

This (deployed to pp23) allows me to repeatedly fetch the homepage without filling up the pool; I'll report back on how well it improves recurring time. We should also deploy to Heroku so that we can compare how things perform without being overwhelmed by the noise of this delay.