Skip to content

Commit 15de9e3

Browse files
authored
add back pressure on derivation pipeline batch queue (#326)
1 parent b5b8941 commit 15de9e3

File tree

2 files changed

+12
-1
lines changed
  • crates

2 files changed

+12
-1
lines changed

crates/derivation-pipeline/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ where
190190
self.metrics.batch_queue_size.set(self.batch_queue.len() as f64);
191191
self.metrics.payload_attributes_queue_size.set(self.attributes_queue.len() as f64);
192192
}
193+
194+
/// Returns the size of the batch queue.
195+
pub fn batch_queue_size(&self) -> usize {
196+
self.batch_queue.len()
197+
}
193198
}
194199

195200
impl<P> Stream for DerivationPipeline<P>

crates/manager/src/manager/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ const CHAIN_ORCHESTRATOR_MAX_PENDING_FUTURES: usize = 20;
7171
/// L1 notification channel.
7272
const ENGINE_MAX_PENDING_FUTURES: usize = 5000;
7373

74+
/// The maximum number of pending batch commits in the derivation pipeline for acceptance of new
75+
/// events from the L1 notification channel.
76+
const DERIVATION_PIPELINE_MAX_PENDING_BATCHES: usize = 500;
77+
7478
/// The main manager for the rollup node.
7579
///
7680
/// This is an endless [`Future`] that drives the state of the entire network forward and includes
@@ -541,7 +545,9 @@ where
541545
let chain_orchestrator_has_capacity = self.chain.pending_futures_len() <
542546
CHAIN_ORCHESTRATOR_MAX_PENDING_FUTURES - L1_NOTIFICATION_CHANNEL_BUDGET as usize;
543547
let engine_has_capacity = self.engine.pending_futures_len() < ENGINE_MAX_PENDING_FUTURES;
544-
chain_orchestrator_has_capacity && engine_has_capacity
548+
let derivation_pipeline_has_capacity =
549+
self.derivation_pipeline.batch_queue_size() < DERIVATION_PIPELINE_MAX_PENDING_BATCHES;
550+
chain_orchestrator_has_capacity && engine_has_capacity && derivation_pipeline_has_capacity
545551
}
546552
}
547553

0 commit comments

Comments
 (0)