Skip to content

Commit

Permalink
change spawn_concurrency_level to be 4 times the number of worker thr…
Browse files Browse the repository at this point in the history
…eads
  • Loading branch information
wathenjiang committed Sep 22, 2023
1 parent 68af71a commit 8e4716a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tokio/src/runtime/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,14 @@ impl Builder {
/// This can be any number greater than 0 and less than or equal to 65536,
/// if the parameter is larger than this value, concurrency level will actually select 65536 internally.
///
/// This should be set according to the expected scale of multi-thread concurrency of `tokio::spawn`,
/// This requires a trade-off between concurrency scale and CPU's cache.
/// When the value of this is small compared to the number of concurrent threads, increasing it
/// will help improve the performanc of concurrently spawn tasks. However, when the value is
/// already large enough, further increasing it will not continue to improve performance.
/// Instead, it may result in longer time of the Runtime creation.
///
/// # Default
///
/// The default value is twice the number of worker threads.
/// The default value for this is 4 times the number of worker threads.
///
/// When using the `current_thread` runtime this method has no effect.
///
Expand Down Expand Up @@ -1282,7 +1284,7 @@ cfg_rt_multi_thread! {
use crate::runtime::scheduler::{self, MultiThread};

let core_threads = self.worker_threads.unwrap_or_else(num_cpus);
let spawn_concurrency_level = self.spawn_concurrency_level.unwrap_or(core_threads * 2);
let spawn_concurrency_level = self.spawn_concurrency_level.unwrap_or(core_threads * 4);

let (driver, driver_handle) = driver::Driver::new(self.get_cfg())?;

Expand Down Expand Up @@ -1332,7 +1334,7 @@ cfg_rt_multi_thread! {
use crate::runtime::scheduler::MultiThreadAlt;

let core_threads = self.worker_threads.unwrap_or_else(num_cpus);
let spawn_concurrency_level = self.spawn_concurrency_level.unwrap_or(core_threads * 2);
let spawn_concurrency_level = self.spawn_concurrency_level.unwrap_or(core_threads * 4);

let (driver, driver_handle) = driver::Driver::new(self.get_cfg())?;

Expand Down

0 comments on commit 8e4716a

Please sign in to comment.