@@ -22,9 +22,8 @@ mod tls;
22
22
use tcp:: { TcpConnWrapper , TcpConnection } ;
23
23
use tls:: { TlsConnWrapper , TlsConnection } ;
24
24
25
- // TODO: Move this to a parameter. This current number is based on a few
26
- // random benchmarks and see whatever gave decent perf vs resource use.
27
- static MAX_CONCURRENT_CONNECTIONS : usize = 50 ;
25
+ // This number is based on a few random benchmarks and see whatever gave decent perf vs resource use.
26
+ const DEFAULT_MAX_CONCURRENT_CONNECTIONS : usize = 50 ;
28
27
29
28
type HttpPool = DashMap < SocketAddr , Pool < TcpStream , std:: io:: Error > > ;
30
29
type HttpsPool = DashMap < SocketAddr , Pool < TlsStream < TcpStream > , Error > > ;
@@ -33,6 +32,7 @@ type HttpsPool = DashMap<SocketAddr, Pool<TlsStream<TcpStream>, Error>>;
33
32
pub struct H1Client {
34
33
http_pools : HttpPool ,
35
34
https_pools : HttpsPool ,
35
+ max_concurrent_connections : usize ,
36
36
}
37
37
38
38
impl Debug for H1Client {
@@ -53,6 +53,16 @@ impl H1Client {
53
53
Self {
54
54
http_pools : DashMap :: new ( ) ,
55
55
https_pools : DashMap :: new ( ) ,
56
+ max_concurrent_connections : DEFAULT_MAX_CONCURRENT_CONNECTIONS ,
57
+ }
58
+ }
59
+
60
+ /// Create a new instance.
61
+ pub fn with_max_connections ( max : usize ) -> Self {
62
+ Self {
63
+ http_pools : DashMap :: new ( ) ,
64
+ https_pools : DashMap :: new ( ) ,
65
+ max_concurrent_connections : max,
56
66
}
57
67
}
58
68
}
@@ -96,8 +106,10 @@ impl HttpClient for H1Client {
96
106
pool
97
107
} else {
98
108
let manager = TcpConnection :: new ( addr) ;
99
- let pool =
100
- Pool :: < TcpStream , std:: io:: Error > :: new ( manager, MAX_CONCURRENT_CONNECTIONS ) ;
109
+ let pool = Pool :: < TcpStream , std:: io:: Error > :: new (
110
+ manager,
111
+ self . max_concurrent_connections ,
112
+ ) ;
101
113
self . http_pools . insert ( addr, pool) ;
102
114
self . http_pools . get ( & addr) . unwrap ( )
103
115
} ;
@@ -114,7 +126,7 @@ impl HttpClient for H1Client {
114
126
let manager = TlsConnection :: new ( host. clone ( ) , addr) ;
115
127
let pool = Pool :: < TlsStream < TcpStream > , Error > :: new (
116
128
manager,
117
- MAX_CONCURRENT_CONNECTIONS ,
129
+ self . max_concurrent_connections ,
118
130
) ;
119
131
self . https_pools . insert ( addr, pool) ;
120
132
self . https_pools . get ( & addr) . unwrap ( )
0 commit comments