Skip to content

Commit 2d635b1

Browse files
committed
env: use available concurrency to set concurrency defaults
1 parent 97d070d commit 2d635b1

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/config.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ pub type HostProvider = FillProvider<
5151
RootProvider,
5252
>;
5353

54+
/// The default concurrency limit for the builder if system call fails.
55+
pub const DEFAULT_CONCURRENCY_LIMIT: usize = 4;
56+
5457
/// Configuration for a builder running a specific rollup on a specific host
5558
/// chain.
5659
#[derive(Debug, Clone, FromEnv)]
@@ -157,7 +160,8 @@ pub struct BuilderConfig {
157160
/// The max number of simultaneous block simulations to run.
158161
#[from_env(
159162
var = "CONCURRENCY_LIMIT",
160-
desc = "The max number of simultaneous block simulations to run"
163+
desc = "The max number of simultaneous block simulations to run",
164+
optional
161165
)]
162166
pub concurrency_limit: usize,
163167

@@ -285,4 +289,14 @@ impl BuilderConfig {
285289
pub const fn cfg_env(&self) -> SignetCfgEnv {
286290
SignetCfgEnv { chain_id: self.ru_chain_id }
287291
}
292+
293+
/// Get the concurrency limit for the current system.
294+
pub fn concurrency_limit(&self) -> usize {
295+
if self.concurrency_limit == 0 {
296+
std::thread::available_parallelism()
297+
.map(|p| p.get())
298+
.unwrap_or(DEFAULT_CONCURRENCY_LIMIT);
299+
}
300+
self.concurrency_limit
301+
}
288302
}

0 commit comments

Comments
 (0)