@@ -123,6 +123,9 @@ pub enum ConfigError {
123
123
/// Error connecting to the signer
124
124
#[ error( "failed to connect to signer: {0}" ) ]
125
125
Signer ( #[ from] SignerError ) ,
126
+ /// Error checking available system concurrency
127
+ #[ error( "failed to determine system concurrency: {0}" ) ]
128
+ Io ( #[ from] std:: io:: Error ) ,
126
129
}
127
130
128
131
impl ConfigError {
@@ -192,7 +195,7 @@ impl BuilderConfig {
192
195
oauth_authenticate_url : load_string ( OAUTH_AUTHENTICATE_URL ) ?,
193
196
oauth_token_url : load_string ( OAUTH_TOKEN_URL ) ?,
194
197
oauth_token_refresh_interval : load_u64 ( AUTH_TOKEN_REFRESH_INTERVAL ) ?,
195
- concurrency_limit : load_u64 ( CONCURRENCY_LIMIT ) . map ( |v| v as usize ) . unwrap_or ( 1000 ) ,
198
+ concurrency_limit : load_concurrency_limit ( ) ? ,
196
199
start_timestamp : load_u64 ( START_TIMESTAMP ) ?,
197
200
} )
198
201
}
@@ -320,3 +323,15 @@ pub fn load_address(key: &str) -> Result<Address, ConfigError> {
320
323
Address :: from_str ( & address)
321
324
. map_err ( |_| ConfigError :: Var ( format ! ( "Invalid address format for {}" , key) ) )
322
325
}
326
+
327
+ /// Checks the configured concurrency parameter and, if none is set, checks the available
328
+ /// system concurrency with `std::thread::available_parallelism` and returns that.
329
+ pub fn load_concurrency_limit ( ) -> Result < usize , ConfigError > {
330
+ match load_u16 ( CONCURRENCY_LIMIT ) {
331
+ Ok ( env) => Ok ( env as usize ) ,
332
+ Err ( _) => {
333
+ let limit = std:: thread:: available_parallelism ( ) ?. get ( ) ;
334
+ Ok ( limit)
335
+ }
336
+ }
337
+ }
0 commit comments