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

maxUses based on time instead of uses #51

Open
intellix opened this issue Feb 25, 2023 · 1 comment
Open

maxUses based on time instead of uses #51

intellix opened this issue Feb 25, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@intellix
Copy link

intellix commented Feb 25, 2023

So we're having the exact same problem that maxUses seems to describe and we're going to implement it (pgbouncer instances are getting 4/5 and 1/5 split of traffic).

It looks great but feels quite difficult to implement dynamically (especially since a server may be long lived, how do you dynamically update the maxUses option based on traffic and how do you even get that data?).

Wouldn't it be much easier to just reconnect every 30 minutes instead of counting uses of a connection?

I'm not too versed in how this library works, but looking at the maxUsesPerInstance code, I believe it would be as simple as a setInterval to swap a flag from false -> true and then calling destroy on release()

@sushantdhiman
Copy link
Collaborator

If I understood correctly, you want to expire a connection after a given time regardless of how many time it was used. We have idleTimeoutMillis but I think it is not suitable for your case, when application is actively using resources this option will not work for cycling connections.

I'm not too versed in how this library works, but looking at the maxUsesPerInstance code, I believe it would be as simple as a setInterval to swap a flag from false -> true and then calling destroy on release()

Not sure about this idea, but I think we have two ways of solving this

  • Provide a expireConnectionAfterMillis (or something similar) option, so a connection is removed if used after certain time
  • Expose internal PooledObject info so application can watch connections and remove them if some condition in application logic satisfied (by calling pool.destroy)

I think (1) looks like a better approach, but it is also really similar to maxUses; implementation should probably provide option to either destroy resource by time or uses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants