-
Notifications
You must be signed in to change notification settings - Fork 142
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
Connection Reaping #125
Comments
I see you mentioned some validity to the overall idea in the other health check thread. I'd be happy to craft the PR for this functionality if we can agree on public facing shape. If you plan on implementing it I'll just keep an eye out. |
I can see a use case for idle connection reaping. I don't like the thought of spinning up a single thread just to reap the pool every 5 minutes (for example) but I don't see any alternative other than checking upon every checkin, which can happen 1000s of times per second. I'll let others implement since I'm not one that would take advantage of the feature. |
@mperham I reviewed the connection reaping in ActiveRecord and it is spawning a sleeping thread (https://github.com/rails/rails/blob/157920aead96865e3135f496c09ace607d5620dc/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L335) If ConnectionPool will handle the termination of the Connections, should it also take a argument to configure the shutdown command?
|
What's old is new again. Sigh. |
This is ridiculous, there's no reason for every client to have their own bespoke method name for the same purpose. I would implement it as |
I mean.. It's not like there's a standardisation body or something like that. So different libraries are bound to use different synonyms. As said in your PR I'm fine with merging the alias in redis-rb, but ultimately you'd have dozens and dozens of similar PRs to submit to many different gems. So allowing to pass a block or method name to |
I'm fine with picking an expected method and calling it a day.
Printing a warning would be fine, but I'm not sure the connection should be reaped since there is no guarantee it is GCable. We could end up leaking the connections by just forgetting them in ConnectionPool. |
Reaping will be opt-in; users need to enable it. The usecase is SaaS databases that have connection limits and/or autoscale based on connections in use. Once connections become idle, they can be closed and then autoscale down events can fire. |
Any update on this? I've a usecase where we have a connection pool of IMAP connections. One pool per account. Gmail and Office365 close the connections uncermoniously after some idle timeout. Any idea what are my options? Reloading the whole pool on one connection timeout seems counter-intutive. Any help is appreciated. Thanks |
@zaidakram send a PR to implement it. No one has done the work. |
Here is the PR I started.on the subject.
#127
@mperham if you can clarity what concurrency issues you saw I can address
them and review moving the logic down into timed stack. I dropped this due
to personal time constraints, sorry I didn't follow up.
@zaidakram we used my PR in production for months without issues before we
dropped the need for reaping, however if there is a concurrency issue, or a
race condition under heavy load you may see usual errors. So use at your
own discretion.
…On Mon, Jul 5, 2021, 11:38 AM Mike Perham ***@***.***> wrote:
@zaidakram <https://github.com/zaidakram> send a PR to implement it. No
one has done the work.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#125 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABQ6MSHSZTR3DKTRZFHWTLTWHGWTANCNFSM4MR56XVA>
.
|
@arjes I don't want a separate reaping thread. |
@mperham I'm not aware of another pattern that would allow for reaping of
unused threads, what were you thinking?
…On Mon, Jul 5, 2021, 3:28 PM Mike Perham ***@***.***> wrote:
@arjes <https://github.com/arjes> I don't want a separate reaping thread.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#125 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABQ6MXXYAJASCIEFRMMTE3TWIBV3ANCNFSM4MR56XVA>
.
|
From what I understand - we could either have a separate reaping thread and close conns by tracking I can see why connection pool having its own thread might create a sort of an indirect liability on applications using it. Esp. considering the after fork behaviors when a fork happens inside process like puma/sidekiq. The thread based reaping would also be in contrast with how activerecord is handling it - https://github.com/rails/rails/blob/a2a870a7360e9590e14e1be989792cd5b607f944/activerecord/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb#L41C17-L41C29 At the same time, I wonder if it still OK to have a dedicated reaping thread if this feature would be opt-in only? Curious about other possible approaches too. Also happy to propose a PR accordingly. |
I want to keep connection pool simple and have no plans to implement this in the gem. As always, connections should be self-repairing and the caller can shutdown old pools and create new pool instances as necessary. |
Hello,
I wanted to open a conversation up about connection reaping and see if this is a feature you would be accept if I opened a PR to provide it.
Our usecase:
We are using AWS's Serverless Aurora, and one of their scaling thresholds is based on number of concurrent connections. Currently we have implemented this by having our connection a layer below ConnectionPool track last query execution time reap the actual RDS connection.
This is getting us our desired behavior, but lacks in one critical area: ConnectionPool still considers that object a full fledged connection and will route requests for connections to them. Ideally the connections would be reaped from the ConnectionPool queue so new connection requests are sent to still-live connections.
If this is behavior you would be willing to accept I'll open the conversation some approaches.
The most obvious approach
Every 5 seconds a connection which hasn't been yielded in 3600s receives
shutdown
(or some other name) and is removed from the queue. It is eligible to be replaced should it be requested.Advantages
Disadvantages
shutdown
method not having it would probably lead to a leaked connection or memory. So the lack of ashutdown
method would probably require reaping be disabledOption 2
Let the connection itself handle it's removal and just expose a method for it to call. While your internal structure is called a Stack you are currently using an array under the hood making this an O(n) operation. For the size of most connection pools I don't consider this a concern.
Advantages
Disadvantages
Thanks for your time, if you are not interested in this feature no problem I'll just fork it for my needs! If not I'll prep a PR with the features we agree are useful.
The text was updated successfully, but these errors were encountered: