Skip to content

Commit 79977bd

Browse files
committed
sets concurrency limit by calling available_parallelism or overriding with env config
1 parent f63fe6b commit 79977bd

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/config.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ pub enum ConfigError {
123123
/// Error connecting to the signer
124124
#[error("failed to connect to signer: {0}")]
125125
Signer(#[from] SignerError),
126+
/// Error checking available system concurrency
127+
#[error("failed to determine system concurrency: {0}")]
128+
Io(#[from] std::io::Error),
126129
}
127130

128131
impl ConfigError {
@@ -192,7 +195,7 @@ impl BuilderConfig {
192195
oauth_authenticate_url: load_string(OAUTH_AUTHENTICATE_URL)?,
193196
oauth_token_url: load_string(OAUTH_TOKEN_URL)?,
194197
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()?,
196199
start_timestamp: load_u64(START_TIMESTAMP)?,
197200
})
198201
}
@@ -320,3 +323,15 @@ pub fn load_address(key: &str) -> Result<Address, ConfigError> {
320323
Address::from_str(&address)
321324
.map_err(|_| ConfigError::Var(format!("Invalid address format for {}", key)))
322325
}
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

Comments
 (0)