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

Shrinking pool size when not in heavy use #299

Open
nyurik opened this issue Jan 12, 2024 · 1 comment
Open

Shrinking pool size when not in heavy use #299

nyurik opened this issue Jan 12, 2024 · 1 comment
Labels
A-core Area: Core / deadpool documentation Improvements or additions to documentation enhancement New feature or request
Milestone

Comments

@nyurik
Copy link

nyurik commented Jan 12, 2024

As reported by user of the Martin tile server, the number of connections to their Postgres database keeps growing until it reaches the pool size, and it never shrinks back, even when the service is mostly not in use. Is this the expected behavior of the deadpool, or is there something deadpool users should do to handle it? Apparently they tried to set keepalives=0, but that didn't change anything. Thx!

@bikeshedder
Copy link
Owner

This is expected as there is no active background process in deadpool.

This is related to those two issues:

At the moment deadpool just cares about the max_size and creates objects as needed. If you need to remove objects from the pool after a given time you can implement your own scheduler which removes objects via the Pool::retain method.

I should add the example from #178 (comment) somewhere in the docs:

let interval = Duration::from_secs(30);
let max_age = Duration::from_secs(60);
tokio::spawn(async move {
    loop {
        tokio::time::sleep(interval).await;
        pool.retain(|_, metrics| metrics.last_used() < max_age);
    }
});

I believe every connection pool is different and baking any kind of behavior into the pool is bound to be wrong for one project or another. So I provide various hooks and introspection methods to roll your own.

I haven't spent much time on this, yet, but I'd like to offer a plugin interface in the future which allows easy addition of such features without changing the core implementation of the pool.

@bikeshedder bikeshedder added documentation Improvements or additions to documentation enhancement New feature or request A-core Area: Core / deadpool labels Jan 16, 2024
@bikeshedder bikeshedder added this to the 0.12 milestone Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core / deadpool documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants