@@ -38,8 +38,10 @@ pub struct ClientStats {
38
38
/// Total time spent waiting for a connection from pool, measures in microseconds
39
39
pub total_wait_time : Arc < AtomicU64 > ,
40
40
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 > ,
43
45
44
46
/// Current state of the client
45
47
pub state : Arc < AtomicClientState > ,
@@ -63,7 +65,7 @@ impl Default for ClientStats {
63
65
username : String :: new ( ) ,
64
66
pool_name : String :: new ( ) ,
65
67
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 ) ) ,
67
69
state : Arc :: new ( AtomicClientState :: new ( ClientState :: Idle ) ) ,
68
70
transaction_count : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
69
71
query_count : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
@@ -111,6 +113,11 @@ impl ClientStats {
111
113
112
114
/// Reports a client is waiting for a connection
113
115
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
+ ) ;
114
121
self . state . store ( ClientState :: Waiting , Ordering :: Relaxed ) ;
115
122
}
116
123
@@ -134,8 +141,6 @@ impl ClientStats {
134
141
pub fn checkout_time ( & self , microseconds : u64 ) {
135
142
self . total_wait_time
136
143
. fetch_add ( microseconds, Ordering :: Relaxed ) ;
137
- self . max_wait_time
138
- . fetch_max ( microseconds, Ordering :: Relaxed ) ;
139
144
}
140
145
141
146
/// Report a query executed by a client against a server
0 commit comments