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

Limit number of redis connections and fix ttl bug #75

Merged
merged 3 commits into from Jan 21, 2020

Conversation

anirbanmu
Copy link
Contributor

  • Previously (before commit a94719b) each gush object that had a method client with a memoized Client.new would create a new redis connection. This was causing a lot of redis connections for us & causing us to hit the limit of our redis instance. With commit a94719b, we now hold only open redis connection per thread via a thread local class variable. This lowers the amount of redis connection substantially.
  • Commit 1c12ce2 fixes a bug where TTL was not being set correct for job key causing job keys to never be expired.

@pokonski
Copy link
Contributor

Hey @anirbanmu. Thanks a bunch for the contribution :) Looks like CI will need some fixing due to bundler upgrade.

@@ -1,9 +1,22 @@
require 'connection_pool'
require 'redis'
require 'concurrent-ruby'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we explicitly use concurrent ruby we should add dependency to .gemspec

@@ -1,9 +1,22 @@
require 'connection_pool'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed as a dependency now

@pokonski
Copy link
Contributor

pokonski commented Jan 15, 2020

General question: instead of reimplementing connnections cache wouldn't it make more sense to cache connection pool?

@anirbanmu
Copy link
Contributor Author

General question: instead of reimplementing connnections cache wouldn't it make more sense to cache connection pool?

Good question. Basically, in my understanding, a connection pool only makes sense if one wants to have a pool of connections that will be shared by multiple consumers. In the design I went with, there is one connection per ruby thread, so there are never multiple consumers for the cached connection. So with the one per thread design, I don't think having a connection pool makes sense.

I think caching a connection pool might make sense, if we changed the design to have a per process connection pool which is then shared by all threads in that process or something like that. That may be a direction worth exploring but I like the cleanliness of not having to worry about a global pool/sharing, and still getting a decrease in # of redis connections.

PS - I fixed travis CI & updated the gemspec as well.

…edis connection.

With this design, each thread has its own redis connection (which is replaced if for some reason
a new redis url is seen (should be unlikely))
…doesn't exist in redis). Added tests to verify as well.
@anirbanmu anirbanmu force-pushed the limit-redis-conn-and-fix-ttl-bug branch from 0dc4643 to 2f0ebe7 Compare January 16, 2020 16:59
@anirbanmu anirbanmu force-pushed the limit-redis-conn-and-fix-ttl-bug branch from 2f0ebe7 to 05a538a Compare January 16, 2020 17:00
@pokonski
Copy link
Contributor

@anirbanmu thanks for the detailed explanation. I agree now that Connection Pooling might wait :)

@pokonski pokonski merged commit 7c89931 into chaps-io:master Jan 21, 2020
@pokonski
Copy link
Contributor

Now time to update the docs and config about connection pools, thank you for your contribution! <3

@anirbanmu anirbanmu deleted the limit-redis-conn-and-fix-ttl-bug branch February 18, 2020 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants