deadpool icon indicating copy to clipboard operation
deadpool copied to clipboard

Feature request: add last_successful_statement metric

Open juchiast opened this issue 10 months ago • 3 comments

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.

juchiast avatar Oct 06 '23 12:10 juchiast

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 avatar Oct 08 '23 13:10 bikeshedder

@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 avatar Oct 16 '23 09:10 bikeshedder

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

juchiast avatar Oct 16 '23 18:10 juchiast