-
Notifications
You must be signed in to change notification settings - Fork 139
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
Feature Request: Support max_lifetime. #359
Comments
This is related to the following issues:
Right now deadpool is completely passive. Unless you call Via the Object::metrics method you can already get to know the age of the connection. The documentation provides an example how you can periodically remove old connections from the pool via the Pool::retain method. 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);
}
}); As this won't catch connections which are in-flight at the time this job runs you should also add a Pool::builder(...)
// ...
.pre_recycle(Hook::sync_fn(|_, metrics| {
if metrics.age() > max_age {
Err(HookError::message("Max age reached"))
} else {
Ok(())
}
}))
// ... While this is a working fix for #299 it doesn't provide the ahead of time recycling and minimum size feature. Yes, this is a feature planned for the future. I haven't come around writing it. The documentation of the hooks lacks some good examples and I haven't come around designing the API for making ahead of time recycling possible. I'm open to suggestions on what kind of additional APIs deadpool needs to provide to make this a reality. I just want to keep the core of deadpool light and passive. I'm confident that a passive pool implementation as basis with hooks and a plugin interfaces is more flexible and robust at the same time. |
Oh, and regarding your questions... Q: Is this feature something you'd consider adding to deadpool? Q: Are there any potential drawbacks or implementation challenges you foresee? Q: Would this feature be specific to PostgreSQL, or could it be implemented generically for all supported databases? |
Description
First of all, thank you for maintaining the deadpool project. It's a valuable tool for connection pooling in Rust applications. I'd like to request a new feature that would enhance the functionality of deadpool, particularly for PostgreSQL connections.
Feature Request
I would like to propose adding support for a max_lifetime feature in deadpool, specifically for PostgreSQL connections. This feature would allow users to set a maximum lifetime for connections in the pool, after which they would be automatically closed and replaced with fresh connections.
Rationale
Proposed Implementation
Example Usage
Questions
Thank you for considering this feature request. I'm happy to provide any additional information or clarification if needed.
The text was updated successfully, but these errors were encountered: