@@ -38,8 +38,10 @@ pub struct ClientStats {
3838 /// Total time spent waiting for a connection from pool, measures in microseconds
3939 pub total_wait_time : Arc < AtomicU64 > ,
4040
41- /// Maximum time spent waiting for a connection from pool, measures in microseconds
42- pub max_wait_time : Arc < AtomicU64 > ,
41+ /// When this client started waiting.
42+ /// Stored as microseconds since connect_time so it can fit in an AtomicU64 instead
43+ /// of us using an "AtomicInstant"
44+ pub wait_start : Arc < AtomicU64 > ,
4345
4446 /// Current state of the client
4547 pub state : Arc < AtomicClientState > ,
@@ -63,7 +65,7 @@ impl Default for ClientStats {
6365 username : String :: new ( ) ,
6466 pool_name : String :: new ( ) ,
6567 total_wait_time : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
66- max_wait_time : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
68+ wait_start : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
6769 state : Arc :: new ( AtomicClientState :: new ( ClientState :: Idle ) ) ,
6870 transaction_count : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
6971 query_count : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
@@ -111,6 +113,11 @@ impl ClientStats {
111113
112114 /// Reports a client is waiting for a connection
113115 pub fn waiting ( & self ) {
116+ // safe to truncate, we only lose info if duration is greater than ~585,000 years
117+ self . wait_start . store (
118+ Instant :: now ( ) . duration_since ( self . connect_time ) . as_micros ( ) as u64 ,
119+ Ordering :: Relaxed ,
120+ ) ;
114121 self . state . store ( ClientState :: Waiting , Ordering :: Relaxed ) ;
115122 }
116123
@@ -134,8 +141,6 @@ impl ClientStats {
134141 pub fn checkout_time ( & self , microseconds : u64 ) {
135142 self . total_wait_time
136143 . fetch_add ( microseconds, Ordering :: Relaxed ) ;
137- self . max_wait_time
138- . fetch_max ( microseconds, Ordering :: Relaxed ) ;
139144 }
140145
141146 /// Report a query executed by a client against a server
0 commit comments