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.
Merge branch 'tokio-rs:master' into master
- Loading branch information
Showing
110 changed files
with
1,797 additions
and
910 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
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
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,109 @@ | ||
use std::time::{Duration, Instant}; | ||
|
||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use tokio::{ | ||
runtime::Runtime, | ||
time::{sleep, timeout}, | ||
}; | ||
|
||
// a very quick async task, but might timeout | ||
async fn quick_job() -> usize { | ||
1 | ||
} | ||
|
||
fn build_run_time(workers: usize) -> Runtime { | ||
if workers == 1 { | ||
tokio::runtime::Builder::new_current_thread() | ||
.enable_all() | ||
.build() | ||
.unwrap() | ||
} else { | ||
tokio::runtime::Builder::new_multi_thread() | ||
.enable_all() | ||
.worker_threads(workers) | ||
.build() | ||
.unwrap() | ||
} | ||
} | ||
|
||
fn single_thread_scheduler_timeout(c: &mut Criterion) { | ||
do_timeout_test(c, 1, "single_thread_timeout"); | ||
} | ||
|
||
fn multi_thread_scheduler_timeout(c: &mut Criterion) { | ||
do_timeout_test(c, 8, "multi_thread_timeout-8"); | ||
} | ||
|
||
fn do_timeout_test(c: &mut Criterion, workers: usize, name: &str) { | ||
let runtime = build_run_time(workers); | ||
c.bench_function(name, |b| { | ||
b.iter_custom(|iters| { | ||
let start = Instant::now(); | ||
runtime.block_on(async { | ||
black_box(spawn_timeout_job(iters as usize, workers).await); | ||
}); | ||
start.elapsed() | ||
}) | ||
}); | ||
} | ||
|
||
async fn spawn_timeout_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(); | ||
} | ||
} | ||
|
||
fn single_thread_scheduler_sleep(c: &mut Criterion) { | ||
do_sleep_test(c, 1, "single_thread_sleep"); | ||
} | ||
|
||
fn multi_thread_scheduler_sleep(c: &mut Criterion) { | ||
do_sleep_test(c, 8, "multi_thread_sleep-8"); | ||
} | ||
|
||
fn do_sleep_test(c: &mut Criterion, workers: usize, name: &str) { | ||
let runtime = build_run_time(workers); | ||
|
||
c.bench_function(name, |b| { | ||
b.iter_custom(|iters| { | ||
let start = Instant::now(); | ||
runtime.block_on(async { | ||
black_box(spawn_sleep_job(iters as usize, workers).await); | ||
}); | ||
start.elapsed() | ||
}) | ||
}); | ||
} | ||
|
||
async fn spawn_sleep_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 = black_box(sleep(Duration::from_secs(1))); | ||
} | ||
})); | ||
} | ||
for handle in handles { | ||
handle.await.unwrap(); | ||
} | ||
} | ||
|
||
criterion_group!( | ||
timeout_benchmark, | ||
single_thread_scheduler_timeout, | ||
multi_thread_scheduler_timeout, | ||
single_thread_scheduler_sleep, | ||
multi_thread_scheduler_sleep | ||
); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
283 | ||
284 | ||
& | ||
+ | ||
< | ||
|
@@ -131,6 +131,7 @@ io | |
IOCP | ||
iOS | ||
IOs | ||
io_uring | ||
IP | ||
IPv4 | ||
IPv6 | ||
|
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,9 @@ | ||
This is used for the `no-atomic-u64-test` ci check that verifies that Tokio | ||
works even if the `AtomicU64` type is missing. | ||
|
||
When increasing the nightly compiler version, you may need to regenerate this | ||
target using the following command: | ||
``` | ||
rustc +nightly -Z unstable-options --print target-spec-json --target i686-unknown-linux-gnu | grep -v 'is-builtin' | sed 's/"max-atomic-width": 64/"max-atomic-width": 32/' > target-specs/i686-unknown-linux-gnu.json | ||
``` | ||
|
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
Oops, something went wrong.