From 3bba41a209e308abdbe8e88f601f365566befa7d Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 14 Jun 2023 18:00:15 +0200 Subject: [PATCH] fix: chunk size edge case (#3143) --- crates/stages/src/stages/sender_recovery.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/stages/src/stages/sender_recovery.rs b/crates/stages/src/stages/sender_recovery.rs index bafa6938f2..9f74ebcd20 100644 --- a/crates/stages/src/stages/sender_recovery.rs +++ b/crates/stages/src/stages/sender_recovery.rs @@ -101,6 +101,11 @@ impl Stage for SenderRecoveryStage { // Chunks are submitted instead of individual transactions to reduce the overhead of work // stealing in the threadpool workers. let chunk_size = self.commit_threshold as usize / rayon::current_num_threads(); + // prevents an edge case + // where the chunk size is either 0 or too small + // to gain anything from using more than 1 thread + let chunk_size = chunk_size.max(16); + for chunk in &tx_walker.chunks(chunk_size) { // An _unordered_ channel to receive results from a rayon job let (recovered_senders_tx, recovered_senders_rx) = mpsc::unbounded_channel();