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 tag 'tokio-1.26.0' into solid-rs/1.x
- Loading branch information
Showing
104 changed files
with
5,012 additions
and
1,115 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
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,53 @@ | ||
use bencher::{benchmark_group, benchmark_main, Bencher}; | ||
use tokio::{ | ||
runtime::Runtime, | ||
sync::{mpsc, oneshot}, | ||
}; | ||
|
||
fn request_reply_current_thread(b: &mut Bencher) { | ||
let rt = tokio::runtime::Builder::new_current_thread() | ||
.build() | ||
.unwrap(); | ||
|
||
request_reply(b, rt); | ||
} | ||
|
||
fn request_reply_multi_threaded(b: &mut Bencher) { | ||
let rt = tokio::runtime::Builder::new_multi_thread() | ||
.worker_threads(1) | ||
.build() | ||
.unwrap(); | ||
|
||
request_reply(b, rt); | ||
} | ||
|
||
fn request_reply(b: &mut Bencher, rt: Runtime) { | ||
let tx = rt.block_on(async move { | ||
let (tx, mut rx) = mpsc::channel::<oneshot::Sender<()>>(10); | ||
tokio::spawn(async move { | ||
while let Some(reply) = rx.recv().await { | ||
reply.send(()).unwrap(); | ||
} | ||
}); | ||
tx | ||
}); | ||
|
||
b.iter(|| { | ||
let task_tx = tx.clone(); | ||
rt.block_on(async move { | ||
for _ in 0..1_000 { | ||
let (o_tx, o_rx) = oneshot::channel(); | ||
task_tx.send(o_tx).await.unwrap(); | ||
let _ = o_rx.await; | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
benchmark_group!( | ||
sync_mpsc_oneshot_group, | ||
request_reply_current_thread, | ||
request_reply_multi_threaded, | ||
); | ||
|
||
benchmark_main!(sync_mpsc_oneshot_group); |
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,64 @@ | ||
use bencher::{black_box, Bencher}; | ||
use rand::prelude::*; | ||
use std::sync::atomic::{AtomicU64, Ordering}; | ||
use std::sync::Arc; | ||
use tokio::sync::{watch, Notify}; | ||
|
||
fn rt() -> tokio::runtime::Runtime { | ||
tokio::runtime::Builder::new_multi_thread() | ||
.worker_threads(6) | ||
.build() | ||
.unwrap() | ||
} | ||
|
||
fn do_work(rng: &mut impl RngCore) -> u32 { | ||
use std::fmt::Write; | ||
let mut message = String::new(); | ||
for i in 1..=10 { | ||
let _ = write!(&mut message, " {i}={}", rng.gen::<f64>()); | ||
} | ||
message | ||
.as_bytes() | ||
.iter() | ||
.map(|&c| c as u32) | ||
.fold(0, u32::wrapping_add) | ||
} | ||
|
||
fn contention_resubscribe(b: &mut Bencher) { | ||
const NTASK: u64 = 1000; | ||
|
||
let rt = rt(); | ||
let (snd, rcv) = watch::channel(0i32); | ||
let wg = Arc::new((AtomicU64::new(0), Notify::new())); | ||
for n in 0..NTASK { | ||
let mut rcv = rcv.clone(); | ||
let wg = wg.clone(); | ||
let mut rng = rand::rngs::StdRng::seed_from_u64(n); | ||
rt.spawn(async move { | ||
while rcv.changed().await.is_ok() { | ||
let _ = *rcv.borrow(); // contend on rwlock | ||
let r = do_work(&mut rng); | ||
let _ = black_box(r); | ||
if wg.0.fetch_sub(1, Ordering::Release) == 1 { | ||
wg.1.notify_one(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
b.iter(|| { | ||
rt.block_on(async { | ||
for _ in 0..100 { | ||
assert_eq!(wg.0.fetch_add(NTASK, Ordering::Relaxed), 0); | ||
let _ = snd.send(black_box(42)); | ||
while wg.0.load(Ordering::Acquire) > 0 { | ||
wg.1.notified().await; | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
bencher::benchmark_group!(contention, contention_resubscribe); | ||
|
||
bencher::benchmark_main!(contention); |
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,25 @@ | ||
//! 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. | ||
|
||
#[macro_use] | ||
extern crate bencher; | ||
|
||
use bencher::{black_box, Bencher}; | ||
|
||
fn time_now_current_thread(bench: &mut Bencher) { | ||
let rt = tokio::runtime::Builder::new_current_thread() | ||
.enable_time() | ||
.build() | ||
.unwrap(); | ||
|
||
bench.iter(|| { | ||
rt.block_on(async { | ||
black_box(tokio::time::Instant::now()); | ||
}) | ||
}) | ||
} | ||
|
||
bencher::benchmark_group!(time_now, time_now_current_thread,); | ||
|
||
bencher::benchmark_main!(time_now); |
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,4 @@ | ||
target | ||
corpus | ||
artifacts | ||
coverage |
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,29 @@ | ||
[package] | ||
name = "tokio-stream-fuzz" | ||
version = "0.0.0" | ||
publish = false | ||
edition = "2018" | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
libfuzzer-sys = "0.4" | ||
tokio-test = { path = "../../tokio-test" } | ||
|
||
[dependencies.tokio-stream] | ||
path = ".." | ||
|
||
|
||
# Prevent this from interfering with workspaces | ||
[workspace] | ||
members = ["."] | ||
|
||
[profile.release] | ||
debug = 1 | ||
|
||
[[bin]] | ||
name = "fuzz_stream_map" | ||
path = "fuzz_targets/fuzz_stream_map.rs" | ||
test = false | ||
doc = false |
Oops, something went wrong.