Skip to content

Commit ea9dc58

Browse files
committed
env: use available concurrency to set concurrency defaults
1 parent 9d5cee1 commit ea9dc58

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)]
@@ -150,7 +153,8 @@ pub struct BuilderConfig {
150153
/// The max number of simultaneous block simulations to run.
151154
#[from_env(
152155
var = "CONCURRENCY_LIMIT",
153-
desc = "The max number of simultaneous block simulations to run"
156+
desc = "The max number of simultaneous block simulations to run",
157+
optional
154158
)]
155159
pub concurrency_limit: usize,
156160

@@ -276,4 +280,14 @@ impl BuilderConfig {
276280
pub const fn cfg_env(&self) -> SignetCfgEnv {
277281
SignetCfgEnv { chain_id: self.ru_chain_id }
278282
}
283+
284+
/// Get the concurrency limit for the current system.
285+
pub fn concurrency_limit(&self) -> usize {
286+
if self.concurrency_limit == 0 {
287+
std::thread::available_parallelism()
288+
.map(|p| p.get())
289+
.unwrap_or(DEFAULT_CONCURRENCY_LIMIT);
290+
}
291+
self.concurrency_limit
292+
}
279293
}

0 commit comments

Comments
 (0)