Skip to content

Commit

Permalink
feat(bin): add single connection benchmark
Browse files Browse the repository at this point in the history
Benchmark neqo-server -> neqo-client 1GB transfer using criterion.
  • Loading branch information
mxinden committed Mar 18, 2024
1 parent ef5caeb commit e85a76c
Show file tree
Hide file tree
Showing 10 changed files with 1,295 additions and 1,146 deletions.
12 changes: 12 additions & 0 deletions neqo-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ regex = { version = "1.9", default-features = false, features = ["unicode-perl"]
tokio = { version = "1", default-features = false, features = ["net", "time", "macros", "rt", "rt-multi-thread"] }
url = { version = "2.5", default-features = false }

[dev-dependencies]
criterion = { version = "0.5", default-features = false, features = ["html_reports", "async_tokio"] }
tokio = { version = "1", default-features = false, features = ["sync"] }

[features]
bench = []

[lib]
# See https://github.com/bheisler/criterion.rs/blob/master/book/src/faq.md#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
bench = false

[[bench]]
name = "main"
harness = false
required-features = ["bench"]
48 changes: 48 additions & 0 deletions neqo-bin/benches/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::{path::PathBuf, str::FromStr};

use criterion::{criterion_group, criterion_main, Criterion, Throughput};

fn benchmark_transfer(c: &mut Criterion) {
neqo_crypto::init_db(PathBuf::from_str("../test-fixture/db").unwrap());

let runtime = tokio::runtime::Runtime::new().unwrap();

let mut group = c.benchmark_group("main");
group.throughput(Throughput::Bytes(1073741824));

let (done_sender, mut done_receiver) = tokio::sync::oneshot::channel();
std::thread::spawn(move || {
tokio::runtime::Runtime::new().unwrap().block_on(async {
let mut server = Box::pin(neqo_bin::server::server(neqo_bin::server::Args::new()));
tokio::select! {
_ = &mut done_receiver => {}
_ = &mut server => {}
}
})
});

group.bench_function("single-connection", |b| {
b.to_async(&runtime).iter(|| async move {
neqo_bin::client::client(neqo_bin::client::Args::new())
.await
.unwrap();
})
});

group.finish();

done_sender.send(()).unwrap();
}

criterion_group! {
name = transfer;
config = Criterion::default().sample_size(10);
targets = benchmark_transfer
}
criterion_main!(transfer);
Loading

0 comments on commit e85a76c

Please sign in to comment.