@@ -38,10 +38,8 @@ 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
- /// 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 > ,
41
+ /// Maximum time spent waiting for a connection from pool, measures in microseconds
42
+ pub max_wait_time : Arc < AtomicU64 > ,
45
43
46
44
/// Current state of the client
47
45
pub state : Arc < AtomicClientState > ,
@@ -65,7 +63,7 @@ impl Default for ClientStats {
65
63
username : String :: new ( ) ,
66
64
pool_name : String :: new ( ) ,
67
65
total_wait_time : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
68
- wait_start : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
66
+ max_wait_time : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
69
67
state : Arc :: new ( AtomicClientState :: new ( ClientState :: Idle ) ) ,
70
68
transaction_count : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
71
69
query_count : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
@@ -109,23 +107,16 @@ impl ClientStats {
109
107
/// Reports a client is done querying the server and is no longer assigned a server connection
110
108
pub fn idle ( & self ) {
111
109
self . state . store ( ClientState :: Idle , Ordering :: Relaxed ) ;
112
- self . wait_start . store ( 0 , Ordering :: Relaxed ) ;
113
110
}
114
111
115
112
/// Reports a client is waiting for a connection
116
113
pub fn waiting ( & self ) {
117
- // safe to truncate, we only lose info if duration is greater than ~585,000 years
118
- self . wait_start . store (
119
- Instant :: now ( ) . duration_since ( self . connect_time ) . as_micros ( ) as u64 ,
120
- Ordering :: Relaxed ,
121
- ) ;
122
114
self . state . store ( ClientState :: Waiting , Ordering :: Relaxed ) ;
123
115
}
124
116
125
117
/// Reports a client is done waiting for a connection and is about to query the server.
126
118
pub fn active ( & self ) {
127
119
self . state . store ( ClientState :: Active , Ordering :: Relaxed ) ;
128
- self . wait_start . store ( 0 , Ordering :: Relaxed ) ;
129
120
}
130
121
131
122
/// Reports a client has failed to obtain a connection from a connection pool
@@ -143,6 +134,8 @@ impl ClientStats {
143
134
pub fn checkout_time ( & self , microseconds : u64 ) {
144
135
self . total_wait_time
145
136
. fetch_add ( microseconds, Ordering :: Relaxed ) ;
137
+ self . max_wait_time
138
+ . fetch_max ( microseconds, Ordering :: Relaxed ) ;
146
139
}
147
140
148
141
/// Report a query executed by a client against a server
0 commit comments