Skip to content

Commit

Permalink
increase thread pool size
Browse files Browse the repository at this point in the history
  • Loading branch information
fgimenez committed Jan 23, 2025
1 parent 161bd66 commit 08475a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 1 addition & 4 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,7 @@ where
) -> Self {
let (incoming_tx, incoming) = std::sync::mpsc::channel();

// The thread pool requires at least 2 threads as it contains a long running sparse trie
// task.
let num_threads =
std::thread::available_parallelism().map_or(2, |num| (num.get() / 2).max(2));
let num_threads = root::thread_pool_size();

let state_root_task_pool = Arc::new(
rayon::ThreadPoolBuilder::new()
Expand Down
16 changes: 12 additions & 4 deletions crates/engine/tree/src/tree/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ use tracing::{debug, error, trace};
/// The level below which the sparse trie hashes are calculated in [`update_sparse_trie`].
const SPARSE_TRIE_INCREMENTAL_LEVEL: usize = 2;

/// Determines the size of the thread pool to be used in [`StateRootTask`].
/// It should be enough to handle all the expected multiproof calculations
/// triggered in parallel (one per state update received) plus two threads used
/// internally in [`StateRootTask`].
///
/// NOTE: this value can be greater than the available cores in the host, it
/// represents the maximum number of threads that can be handled by the pool.
pub(crate) fn thread_pool_size() -> usize {
std::thread::available_parallelism().map_or(16, |num| (num.get() / 2).max(16))
}

/// Outcome of the state root computation, including the state root itself with
/// the trie updates and the total time spent.
#[derive(Debug)]
Expand Down Expand Up @@ -949,10 +960,7 @@ mod tests {
prefix_sets: Arc::new(input.prefix_sets),
};

// The thread pool requires at least 2 threads as it contains a long running sparse trie
// task.
let num_threads =
std::thread::available_parallelism().map_or(4, |num| (num.get() / 2).max(4));
let num_threads = thread_pool_size();

let state_root_task_pool = rayon::ThreadPoolBuilder::new()
.num_threads(num_threads)
Expand Down

0 comments on commit 08475a3

Please sign in to comment.