Clear active connections after initialization #28057

Merged
merged 1 commit into from Apr 3, 2017

Conversation

Projects
None yet
5 participants
@eugeneius
Member

eugeneius commented Feb 18, 2017

Any connections that were checked out during initialization should be checked back in before the first request is processed, for two reasons:

  • Returning the connection to the pool allows it to be health checked before it's used again. If the connection dies before the first request arrives, the health check will replace it with a new one.

  • If the thread that initialized Rails is not the same thread that will be performing work, checking in the connection will allow it to be reused instead of being stuck to the initialization thread forever.

The second use case was the reason I wrote this patch - we run a lot of Sidekiq processes at @intercom, and deploying this reduced the peak open connection count on our database by 13%.

Clear active connections after initialization
Any connections that were checked out during initialization should be
checked back in before the first request is processed, for two reasons:

 - Returning the connection to the pool allows it to be health checked
   before it's used again. If the connection dies before the first
   request arrives, the health check will replace it with a new one.

 - If the thread that initialized Rails is not the same thread that will
   be performing work, checking in the connection will allow it to be
   reused instead of being stuck to the initialization thread forever.
@rails-bot

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot Feb 18, 2017

r? @schneems

(@rails-bot has picked a reviewer for you, use r? to override)

r? @schneems

(@rails-bot has picked a reviewer for you, use r? to override)

@matthewd matthewd merged commit 3ecffab into rails:master Apr 3, 2017

2 checks passed

codeclimate no new or fixed issues
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment