1
1
use std:: { cell:: Cell , cell:: RefCell , collections:: VecDeque , fmt, rc:: Rc , time:: Duration } ;
2
2
3
3
use nanorand:: { Rng , WyRand } ;
4
- use ntex_bytes:: { ByteString , PoolId , PoolRef } ;
4
+ use ntex_bytes:: ByteString ;
5
5
use ntex_http:: { uri:: Scheme , HeaderMap , Method } ;
6
6
use ntex_io:: IoBoxed ;
7
7
use ntex_net:: connect:: { self as connect, Address , Connect , Connector as DefaultConnector } ;
@@ -136,7 +136,6 @@ impl Client {
136
136
notify ( & mut waiters2. borrow_mut ( ) ) ;
137
137
} ) ;
138
138
// construct client
139
- io. set_memory_pool ( inner. pool ) ;
140
139
let client = SimpleClient :: with_params (
141
140
io,
142
141
inner. config . clone ( ) ,
@@ -145,6 +144,9 @@ impl Client {
145
144
storage,
146
145
) ;
147
146
inner. connections . borrow_mut ( ) . push ( client. clone ( ) ) ;
147
+ inner
148
+ . total_connections
149
+ . set ( inner. total_connections . get ( ) + 1 ) ;
148
150
Ok ( client)
149
151
}
150
152
Ok ( Err ( err) ) => Err ( ClientError :: from ( err) ) ,
@@ -154,6 +156,10 @@ impl Client {
154
156
for waiter in waiters. borrow_mut ( ) . drain ( ..) {
155
157
let _ = waiter. send ( ( ) ) ;
156
158
}
159
+
160
+ if res. is_err ( ) {
161
+ inner. connect_errors . set ( inner. connect_errors . get ( ) + 1 ) ;
162
+ }
157
163
let _ = tx. send ( res) ;
158
164
} ) ;
159
165
return rx
@@ -212,6 +218,28 @@ impl Client {
212
218
}
213
219
}
214
220
221
+ #[ doc( hidden) ]
222
+ impl Client {
223
+ pub fn stat_active_connections ( & self ) -> usize {
224
+ self . inner . connections . borrow ( ) . len ( )
225
+ }
226
+
227
+ pub fn stat_total_connections ( & self ) -> usize {
228
+ self . inner . total_connections . get ( )
229
+ }
230
+
231
+ pub fn stat_connect_errors ( & self ) -> usize {
232
+ self . inner . connect_errors . get ( )
233
+ }
234
+
235
+ pub fn stat_connections < F , R > ( & self , f : F ) -> R
236
+ where
237
+ F : FnOnce ( & [ SimpleClient ] ) -> R ,
238
+ {
239
+ f ( & * self . inner . connections . borrow ( ) )
240
+ }
241
+ }
242
+
215
243
/// Manages http client network connectivity.
216
244
///
217
245
/// The `ClientBuilder` type uses a builder-like combinator pattern for service
@@ -229,9 +257,10 @@ struct Inner {
229
257
config : crate :: Config ,
230
258
authority : ByteString ,
231
259
connector : Connector ,
232
- pool : PoolRef ,
233
260
connecting : Cell < bool > ,
234
261
connections : RefCell < Vec < SimpleClient > > ,
262
+ total_connections : Cell < usize > ,
263
+ connect_errors : Cell < usize > ,
235
264
}
236
265
237
266
impl ClientBuilder {
@@ -268,7 +297,8 @@ impl ClientBuilder {
268
297
config : crate :: Config :: client ( ) ,
269
298
connecting : Cell :: new ( false ) ,
270
299
connections : Default :: default ( ) ,
271
- pool : PoolId :: P5 . pool_ref ( ) ,
300
+ total_connections : Cell :: new ( 0 ) ,
301
+ connect_errors : Cell :: new ( 0 ) ,
272
302
} )
273
303
}
274
304
@@ -289,15 +319,6 @@ impl ClientBuilder {
289
319
self
290
320
}
291
321
292
- /// Set memory pool.
293
- ///
294
- /// Use specified memory pool for memory allocations. By default P5
295
- /// memory pool is used.
296
- pub fn memory_pool ( mut self , id : PoolId ) -> Self {
297
- self . 0 . pool = id. pool_ref ( ) ;
298
- self
299
- }
300
-
301
322
/// Connection timeout.
302
323
///
303
324
/// i.e. max time to connect to remote host including dns name resolution.
@@ -416,7 +437,6 @@ impl fmt::Debug for Client {
416
437
. field ( "minconn" , & self . inner . minconn )
417
438
. field ( "maxconn" , & self . inner . maxconn )
418
439
. field ( "max-streams" , & self . inner . max_streams )
419
- . field ( "pool" , & self . inner . pool )
420
440
. field ( "config" , & self . inner . config )
421
441
. finish ( )
422
442
}
@@ -433,7 +453,6 @@ impl fmt::Debug for ClientBuilder {
433
453
. field ( "minconn" , & self . 0 . minconn )
434
454
. field ( "maxconn" , & self . 0 . maxconn )
435
455
. field ( "max-streams" , & self . 0 . max_streams )
436
- . field ( "pool" , & self . 0 . pool )
437
456
. field ( "config" , & self . 0 . config )
438
457
. finish ( )
439
458
}
0 commit comments