Closed casperisfine closed 2 years ago
Here's what keeping track of instances in a WeakMap would involve: https://github.com/casperisfine/connection_pool/commit/3ff19dd80d12cf2c6656caf4900d802f57b70768.
Thanks! ❤️
A new release is planned to integrate this PR?
Eventually. Do you need it soon for some reason?
Periodically, nearly restart or scaling event, we have more connections open than the theoretical count. We don't investigate a lot because we have needed to upscale Redis plan for other reasons and pics it's never more than 2x higher than the theoretical count. But we would appreciate updating our gem with this feature only to see if it resolves our problem.
You could run main, right?
We could. It's not very clean, but we could.
I could use the feedback, let me know if it helps. Not sure what you mean by clean, it’s one line in your Gemfile.
I could use the feedback, let me know if it helps.
We've been running 428c06f34209ee7a99f1ace5b96e567841c00d1c for a couple months now without any issues on a system that's probably processed 40 million jobs over the time.
2.4.0 is out with this new feature.
Fix: https://github.com/mperham/connection_pool/issues/165
Using connections inherited from a parent process can have very nasty consequences and it's pretty much never desired.
This patch use the
Process._fork
API added in Ruby 3.1 to automatically detect when a fork is happening, and when it does, drop all existing connections.Notes
Performance
ObjectSpace.each_object
is very slow for large applications:So I'd really recommend to keep track of instance with
ObjectSpace::WeakMap
. I'll push a commit in another branch and let you decide.Connection closing
Since
ConnectionPool
doesn't know how to close a connection, this feature simply drop the references, and assume the Ruby GC will do the right thing.