Skip to content

Commit 9b654c1

Browse files
authored
chore: reduce noise in benchmarks (tokio-rs#151)
Removes FuturesUnordered from benchmarks and alters timing to ignore task spawning, as to hone in on specifically the processing of ops and driver performance.
1 parent d649652 commit 9b654c1

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ bytes = { version = "1.0", optional = true }
2828
tempfile = "3.2.0"
2929
tokio-test = "0.4.2"
3030
iai = "0.1.1"
31-
futures = "0.3.25"
3231
criterion = "0.4.0"
3332
# we use joinset in our tests
34-
tokio = "1.21.0"
33+
tokio = "1.21.2"
3534
nix = "0.26.1"
3635

3736
[package.metadata.docs.rs]
3837
all-features = true
3938

39+
[profile.bench]
40+
debug = true
41+
4042
[[bench]]
4143
name = "lai_no_op"
4244
path = "benches/lai/no_op.rs"

benches/criterion/no_op.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use criterion::{
33
};
44
use std::time::{Duration, Instant};
55

6-
use futures::stream::{self, StreamExt};
6+
use tokio::task::JoinSet;
77

88
#[derive(Clone)]
99
struct Options {
@@ -26,11 +26,7 @@ impl Default for Options {
2626

2727
fn run_no_ops(opts: &Options, count: u64) -> Duration {
2828
let mut ring_opts = tokio_uring::uring_builder();
29-
ring_opts
30-
.setup_cqsize(opts.cq_size as _)
31-
// .setup_sqpoll(10)
32-
// .setup_sqpoll_cpu(1)
33-
;
29+
ring_opts.setup_cqsize(opts.cq_size as _);
3430

3531
let mut m = Duration::ZERO;
3632

@@ -40,12 +36,18 @@ fn run_no_ops(opts: &Options, count: u64) -> Duration {
4036
.entries(opts.sq_size as _)
4137
.uring_builder(&ring_opts)
4238
.start(async move {
39+
let mut js = JoinSet::new();
40+
41+
for _ in 0..opts.iterations {
42+
js.spawn_local(tokio_uring::no_op());
43+
}
44+
4345
let start = Instant::now();
44-
stream::iter(0..opts.iterations)
45-
.for_each_concurrent(Some(opts.concurrency), |_| async move {
46-
tokio_uring::no_op().await.unwrap();
47-
})
48-
.await;
46+
47+
while let Some(res) = js.join_next().await {
48+
res.unwrap().unwrap();
49+
}
50+
4951
start.elapsed()
5052
})
5153
}

benches/lai/no_op.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use futures::stream::{self, StreamExt};
21
use iai::black_box;
2+
use tokio::task::JoinSet;
33

44
#[derive(Clone)]
55
struct Options {
@@ -23,11 +23,7 @@ impl Default for Options {
2323
fn runtime_only() -> Result<(), Box<dyn std::error::Error>> {
2424
let opts = Options::default();
2525
let mut ring_opts = tokio_uring::uring_builder();
26-
ring_opts
27-
.setup_cqsize(opts.cq_size as _)
28-
// .setup_sqpoll(10)
29-
// .setup_sqpoll_cpu(1)
30-
;
26+
ring_opts.setup_cqsize(opts.cq_size as _);
3127

3228
tokio_uring::builder()
3329
.entries(opts.sq_size as _)
@@ -37,21 +33,22 @@ fn runtime_only() -> Result<(), Box<dyn std::error::Error>> {
3733

3834
fn run_no_ops(opts: Options) -> Result<(), Box<dyn std::error::Error>> {
3935
let mut ring_opts = tokio_uring::uring_builder();
40-
ring_opts
41-
.setup_cqsize(opts.cq_size as _)
42-
// .setup_sqpoll(10)
43-
// .setup_sqpoll_cpu(1)
44-
;
36+
ring_opts.setup_cqsize(opts.cq_size as _);
4537

4638
tokio_uring::builder()
4739
.entries(opts.sq_size as _)
4840
.uring_builder(&ring_opts)
4941
.start(async move {
50-
stream::iter(0..opts.iterations)
51-
.for_each_concurrent(Some(opts.concurrency), |_| async move {
52-
tokio_uring::no_op().await.unwrap();
53-
})
54-
.await;
42+
let mut js = JoinSet::new();
43+
44+
for _ in 0..opts.iterations {
45+
js.spawn_local(tokio_uring::no_op());
46+
}
47+
48+
while let Some(res) = js.join_next().await {
49+
res.unwrap().unwrap();
50+
}
51+
5552
Ok(())
5653
})
5754
}

0 commit comments

Comments
 (0)