-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add benchmarks for no-op submission (#144)
Co-authored-by: ollie-etl <Oliver Bunting@etlsystems.com>
- Loading branch information
Showing
4 changed files
with
183 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use criterion::{ | ||
criterion_group, criterion_main, BenchmarkId, Criterion, SamplingMode, Throughput, | ||
}; | ||
use std::time::{Duration, Instant}; | ||
|
||
use futures::stream::{self, StreamExt}; | ||
|
||
#[derive(Clone)] | ||
struct Options { | ||
iterations: usize, | ||
concurrency: usize, | ||
sq_size: usize, | ||
cq_size: usize, | ||
} | ||
|
||
impl Default for Options { | ||
fn default() -> Self { | ||
Self { | ||
iterations: 100000, | ||
concurrency: 1, | ||
sq_size: 128, | ||
cq_size: 256, | ||
} | ||
} | ||
} | ||
|
||
fn run_no_ops(opts: &Options, count: u64) -> Duration { | ||
let mut ring_opts = tokio_uring::uring_builder(); | ||
ring_opts | ||
.setup_cqsize(opts.cq_size as _) | ||
// .setup_sqpoll(10) | ||
// .setup_sqpoll_cpu(1) | ||
; | ||
|
||
let mut m = Duration::ZERO; | ||
|
||
// Run the required number of iterations | ||
for _ in 0..count { | ||
m += tokio_uring::builder() | ||
.entries(opts.sq_size as _) | ||
.uring_builder(&ring_opts) | ||
.start(async move { | ||
let start = Instant::now(); | ||
stream::iter(0..opts.iterations) | ||
.for_each_concurrent(Some(opts.concurrency), |_| async move { | ||
tokio_uring::no_op().await.unwrap(); | ||
}) | ||
.await; | ||
start.elapsed() | ||
}) | ||
} | ||
m | ||
} | ||
|
||
fn bench(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("no_op"); | ||
let mut opts = Options::default(); | ||
for concurrency in [1, 32, 64, 256].iter() { | ||
opts.concurrency = *concurrency; | ||
|
||
// We perform long running benchmarks: this is the best mode | ||
group.sampling_mode(SamplingMode::Flat); | ||
|
||
group.throughput(Throughput::Elements(opts.iterations as u64)); | ||
group.bench_with_input( | ||
BenchmarkId::from_parameter(concurrency), | ||
&opts, | ||
|b, opts| { | ||
// Custom iterator used because we don't expose access to runtime, | ||
// which is required to do async benchmarking with criterion | ||
b.iter_custom(move |iter| run_no_ops(opts, iter)); | ||
}, | ||
); | ||
} | ||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, bench); | ||
criterion_main!(benches); |
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,83 @@ | ||
use futures::stream::{self, StreamExt}; | ||
use iai::black_box; | ||
|
||
#[derive(Clone)] | ||
struct Options { | ||
iterations: usize, | ||
concurrency: usize, | ||
sq_size: usize, | ||
cq_size: usize, | ||
} | ||
|
||
impl Default for Options { | ||
fn default() -> Self { | ||
Self { | ||
iterations: 100000, | ||
concurrency: 1, | ||
sq_size: 64, | ||
cq_size: 256, | ||
} | ||
} | ||
} | ||
|
||
fn runtime_only() -> Result<(), Box<dyn std::error::Error>> { | ||
let opts = Options::default(); | ||
let mut ring_opts = tokio_uring::uring_builder(); | ||
ring_opts | ||
.setup_cqsize(opts.cq_size as _) | ||
// .setup_sqpoll(10) | ||
// .setup_sqpoll_cpu(1) | ||
; | ||
|
||
tokio_uring::builder() | ||
.entries(opts.sq_size as _) | ||
.uring_builder(&ring_opts) | ||
.start(async move { black_box(Ok(())) }) | ||
} | ||
|
||
fn run_no_ops(opts: Options) -> Result<(), Box<dyn std::error::Error>> { | ||
let mut ring_opts = tokio_uring::uring_builder(); | ||
ring_opts | ||
.setup_cqsize(opts.cq_size as _) | ||
// .setup_sqpoll(10) | ||
// .setup_sqpoll_cpu(1) | ||
; | ||
|
||
tokio_uring::builder() | ||
.entries(opts.sq_size as _) | ||
.uring_builder(&ring_opts) | ||
.start(async move { | ||
stream::iter(0..opts.iterations) | ||
.for_each_concurrent(Some(opts.concurrency), |_| async move { | ||
tokio_uring::no_op().await.unwrap(); | ||
}) | ||
.await; | ||
Ok(()) | ||
}) | ||
} | ||
|
||
// This provides a baseline for estimating op overhead on top of this | ||
fn no_op_x1() -> Result<(), Box<dyn std::error::Error>> { | ||
let opts = Options::default(); | ||
run_no_ops(black_box(opts)) | ||
} | ||
|
||
fn no_op_x32() -> Result<(), Box<dyn std::error::Error>> { | ||
let mut opts = Options::default(); | ||
opts.concurrency = 32; | ||
run_no_ops(black_box(opts)) | ||
} | ||
|
||
fn no_op_x64() -> Result<(), Box<dyn std::error::Error>> { | ||
let mut opts = Options::default(); | ||
opts.concurrency = 64; | ||
run_no_ops(black_box(opts)) | ||
} | ||
|
||
fn no_op_x256() -> Result<(), Box<dyn std::error::Error>> { | ||
let mut opts = Options::default(); | ||
opts.concurrency = 256; | ||
run_no_ops(black_box(opts)) | ||
} | ||
|
||
iai::main!(runtime_only, no_op_x1, no_op_x32, no_op_x64, no_op_x256); |