Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track owning thread for connection pool #14360

Merged
merged 2 commits into from
Mar 18, 2014

Conversation

matthewd
Copy link
Member

Now, if a thread checks out a connection then dies, we can immediately recover that connection and re-use it.

This should alleviate the pool exhaustion discussed in #12867. More importantly, it entirely avoids the potential issues of the reaper attempting to check whether connections are still active: as long as the owning thread is alive, the connection is its business alone.

/cc @tenderlove @jeremy

I kept the #reset! fix in a separate commit... it seems unrelated, apart from having been spotted while dealing with this. Let me know if it should be squashed anyway.

@jeremy
Copy link
Member

jeremy commented Mar 16, 2014

Nice. Looks good.

@tenderlove
Copy link
Member

Agree.

@tenderlove
Copy link
Member

@matthewd can you rebase this and I'll merge it in?

It wasn't doing anything beyond clearing the statement cache.
.. not a general timeout.

Now, if a thread checks out a connection then dies, we can immediately
recover that connection and re-use it.

This should alleviate the pool exhaustion discussed in rails#12867. More
importantly, it entirely avoids the potential issues of the reaper
attempting to check whether connections are still active: as long as the
owning thread is alive, the connection is its business alone.

As a no-op reap is now trivial (only entails checking a thread status
per connection), we can also perform one in-line any time we decide to
sleep for a connection.
tenderlove added a commit that referenced this pull request Mar 18, 2014
Track owning thread for connection pool
@tenderlove tenderlove merged commit 8f21826 into rails:master Mar 18, 2014
@matthargett
Copy link

will this be merged into 4-0-stable? we are having major issues with exhaustion issues on Heroku with PG when a connection gets interrupted in Sidekiq and never gets reaped. This wasn't nearly as much of a problem in 3.2.13-17, so this has proven to be a fairly crippling regression for us.

Thanks for holistically attacking this issue in this pull request and several others!

@rafaelfranca
Copy link
Member

No it will not. Although it is a bug fix it may introduce a regression in a stable version. We prefer to keep it only at 4.1.x

@matthargett
Copy link

Fair enough, for I don't see it in 4-1-stable branch either. Any ETA on when it will be incorporated there?

@rafaelfranca
Copy link
Member

Oh, my mistake I thought it was there. Since it is not the same rule applies for 4.1.x, we will see it only on 4.2

@SamSaffron
Copy link
Contributor

@matthewd @tenderlove this totally breaks us, we need to be able to track last_use otherwise we have no way to drain the pool on inactivity.

see:

https://github.com/discourse/discourse/blob/master/lib/freedom_patches/pool_drainer.rb

@matthewd matthewd deleted the thread_aware_reaper branch August 22, 2015 19:34
byroot added a commit to byroot/rails that referenced this pull request Aug 16, 2024
The reaper was introduced back in cde7692
The goal is to detect checked out connections owned by dead threads, and
make them available again.

To do this, a thread check connections every 60 seconds, which IMO isn't
nearly enough. But more importabtly since rails#14360
the reaper isn't really useful because in the checkout path, if we can't
immediately checkout a connection, we execute the reaping routine, so IMO
it's not really justified to have a background thread for this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants