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

Feature request: add last_successful_statement metric #275

Open
juchiast opened this issue Oct 6, 2023 · 3 comments
Open

Feature request: add last_successful_statement metric #275

juchiast opened this issue Oct 6, 2023 · 3 comments
Labels
A-core Area: Core / deadpool question Further information is requested
Milestone

Comments

@juchiast
Copy link

juchiast commented Oct 6, 2023

Add last_successful_statement: Option<Instant> to Metrics.

Use case: can be used as a heuristic for connection health check. For example, don't do health check if last_successful_statement is less than 5 secs.

I tried last_used, but it's always 0ms right after you get the connection from the pool, therefore not useful.

@bikeshedder
Copy link
Owner

last_used is set on retrieval from the pool. You can access the old metrics from inside a pre_recycle hook which also allows you to drop connections. Added benefit is that the pool will automatically try the next connection in the pool and the code calling Pool::get doesn't have to handle that.

@bikeshedder bikeshedder added A-core Area: Core / deadpool question Further information is requested labels Oct 8, 2023
@bikeshedder
Copy link
Owner

@juchiast Does this fix your issue or do you still need a way to access this information from within code that uses the pool?

btw. you're right in a way that the last_used metric is pretty much useless outside of the hooks. It might make sense to add a last_used instant which returns the previous usage and not the current one:

 pub struct Metrics {
     pub created: Instant,
     pub recycled: Option<Instant>,
     pub recycle_count: usize,
+    pub last_used: Option<Instant>,
 }

@bikeshedder bikeshedder added this to the 0.11 (maybe 1.0) milestone Oct 16, 2023
@juchiast
Copy link
Author

Hi, thanks for the help! I was able to use hook for my code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core / deadpool question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants