forked from tokio-rs/tokio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit is part of reducing timeout performance overhead.
See tokio-rs#6504 Below are relevant benchmark results of this PR on m1 mac: single_thread_timeout time: [21.869 ns 21.987 ns 22.135 ns] change: [-3.4429% -2.0709% -0.8759%] (p = 0.00 < 0.05) Change within noise threshold. Found 7 outliers among 100 measurements (7.00%) 3 (3.00%) high mild 4 (4.00%) high severe multi_thread_timeout-8 time: [4.4835 ns 4.6138 ns 4.7614 ns] change: [-4.3554% +0.1643% +4.5114%] (p = 0.95 > 0.05) No change in performance detected. Found 9 outliers among 100 measurements (9.00%) 8 (8.00%) high mild 1 (1.00%) high severe Below are relevant benchmark results of current version on m1 mac: single_thread_timeout time: [40.227 ns 40.416 ns 40.691 ns] change: [+81.321% +82.817% +84.121%] (p = 0.00 < 0.05) Performance has regressed. Found 14 outliers among 100 measurements (14.00%) 3 (3.00%) high mild 11 (11.00%) high severe multi_thread_timeout-8 time: [183.16 ns 186.02 ns 188.21 ns] change: [+3765.0% +3880.4% +3987.4%] (p = 0.00 < 0.05) Performance has regressed. Found 10 outliers among 100 measurements (10.00%) 4 (4.00%) low severe 6 (6.00%) low mild
- Loading branch information
1 parent
a73d6bf
commit bde0742
Showing
4 changed files
with
114 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//! Benchmark spawning a task onto the basic and threaded Tokio executors. | ||
//! This essentially measure the time to enqueue a task in the local and remote | ||
//! case. | ||
|
||
use std::time::{Duration, Instant}; | ||
|
||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use tokio::time::timeout; | ||
|
||
// a vevry quick async task, but might timeout | ||
async fn quick_job() -> usize { | ||
1 | ||
} | ||
|
||
fn single_thread_scheduler_timeout(c: &mut Criterion) { | ||
do_test(c, 1, "single_thread_timeout"); | ||
} | ||
|
||
fn multi_thread_scheduler_timeout(c: &mut Criterion) { | ||
do_test(c, 8, "multi_thread_timeout-8"); | ||
} | ||
|
||
fn do_test(c: &mut Criterion, workers: usize, name: &str) { | ||
let runtime = tokio::runtime::Builder::new_multi_thread() | ||
.enable_all() | ||
.worker_threads(workers) | ||
.build() | ||
.unwrap(); | ||
|
||
c.bench_function(name, |b| { | ||
b.iter_custom(|iters| { | ||
let start = Instant::now(); | ||
runtime.block_on(async { | ||
black_box(spawn_job(iters as usize, workers).await); | ||
}); | ||
start.elapsed() | ||
}) | ||
}); | ||
} | ||
|
||
async fn spawn_job(iters: usize, procs: usize) { | ||
let mut handles = Vec::with_capacity(procs); | ||
for _ in 0..procs { | ||
handles.push(tokio::spawn(async move { | ||
for _ in 0..iters / procs { | ||
let h = timeout(Duration::from_secs(1), quick_job()); | ||
assert_eq!(black_box(h.await.unwrap()), 1); | ||
} | ||
})); | ||
} | ||
for handle in handles { | ||
handle.await.unwrap(); | ||
} | ||
} | ||
|
||
criterion_group!( | ||
timeout_benchmark, | ||
single_thread_scheduler_timeout, | ||
multi_thread_scheduler_timeout, | ||
); | ||
|
||
criterion_main!(timeout_benchmark); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters