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

Implement TrimPool #213

Closed
wants to merge 1 commit into from
Closed

Implement TrimPool #213

wants to merge 1 commit into from

Conversation

nvivo
Copy link

@nvivo nvivo commented Mar 30, 2017

This is an idea to work around Connection Lifetime that should have a similar effect. Related to #211.

This patch transforms ClearPool into TrimPool, and makes ClearPool = TrimPool(conectionsToKeep: 0);

Then it adds a static method MySqlConnection.TrimPool(int connectionsToKeep) that should release only the required number of connections to keep the pool at some sane size without releasing more than required.

Ideally, it would be better to trim connections based on lifetime, but I'm not confortable changing this codebase yet to add this. If it was possible to add some method like "TrimPool(TimeSpan)" that would trim based on idle time, I could easily implement the timer on the app side calling it every 3 minutes or so.

@bgrainger
Copy link
Member

Would having MinimumPoolSize #85 implemented solve your problem? Then you could set MinimumPoolSize=20; MaximumPoolSize={your peak usage} and calling ClearPool would remove all but 20 idle connections.

And if the watchdog thread were implemented, it seems like no manual workarounds would be necessary; after a few minutes, idle connections would be cleaned up automatically.

@nvivo
Copy link
Author

nvivo commented Mar 30, 2017

@bgrainger Yes, this is quite a dirty workaround, I wouldn't leave it there if there are better options. As I just commented here, after some extra thinking, it seems Maximum Pool Size is a better workaround, so I'll close this.

But as for a solution, only a watchdog would really work. See, ideally, I don't want to set a minimum number of connections to leave open, neither a maximum. If my node is idle, it should have zero connections to the database. If it's at peak, I'd like to pool as many as needed. During these peak times, I may reuse those 100's connections for a while, so I don't really want to lose the pool. Once those connections are not used anymore for 30 seconds or so, they can be released.

It seems that having a miminum pool size would work to keep latency at minimum on a webserver, but that's not my case. these are background services.

So, for now, a Max pool size would be my workaround, it will cause a lot of connections to keep opening and closing, but I don't have any latency requirements on these servers, I don't mind paying this price now.

@nvivo nvivo closed this Mar 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants