Skip to content

Commit e1f9b98

Browse files
committed
feat(test-fixtures): add http3 support to Simulator
Enables benchmarking of mozilla#2796. Fixes mozilla#2728. Fixes mozilla#2804.
1 parent 1b16f83 commit e1f9b98

File tree

4 files changed

+478
-67
lines changed

4 files changed

+478
-67
lines changed

neqo-http3/Cargo.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ ignored = ["log"]
4949
# See https://github.com/bheisler/criterion.rs/blob/master/book/src/faq.md#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
5050
bench = false
5151

52-
# FIXME: These benches have a high rate of variability and are hence not very useful
53-
# in their current form. See https://github.com/mozilla/neqo/issues/2804
54-
# [[bench]]
55-
# name = "streams"
56-
# harness = false
57-
# required-features = ["bench"]
52+
[[bench]]
53+
name = "streams"
54+
harness = false
55+
required-features = ["bench"]

neqo-http3/benches/streams.rs

Lines changed: 35 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,77 +6,51 @@
66

77
#![expect(clippy::unwrap_used, reason = "OK in a bench.")]
88

9-
use std::{hint::black_box, iter::repeat_with};
9+
use std::{hint::black_box, time::Duration};
1010

11-
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
12-
use neqo_crypto::AuthenticationStatus;
13-
use neqo_http3::{Http3Client, Http3Parameters, Http3Server, Priority};
14-
use neqo_transport::{ConnectionParameters, StreamType};
11+
use criterion::{criterion_group, criterion_main, Criterion, Throughput};
1512
use test_fixture::{
16-
fixture_init, http3_client_with_params, http3_server_with_params, now, DEFAULT_SERVER_NAME,
13+
boxed, fixture_init,
14+
sim::{
15+
http3_connection::{Node, Request, Response},
16+
network::RandomDelay,
17+
Simulator,
18+
},
1719
};
1820

19-
const STREAM_TYPE: StreamType = StreamType::BiDi;
20-
const STREAMS_MAX: u64 = 1 << 60;
21-
22-
fn use_streams(client: &mut Http3Client, server: &mut Http3Server, streams: usize, data: &[u8]) {
23-
let stream_ids = repeat_with(|| {
24-
client
25-
.fetch(
26-
now(),
27-
"GET",
28-
&("https", DEFAULT_SERVER_NAME, "/"),
29-
&[],
30-
Priority::default(),
31-
)
32-
.unwrap()
33-
})
34-
.take(streams)
35-
.collect::<Vec<_>>();
36-
exchange_packets(client, server, false);
37-
for stream_id in &stream_ids {
38-
client.send_data(*stream_id, data).unwrap();
39-
}
40-
exchange_packets(client, server, false);
41-
for stream_id in &stream_ids {
42-
client.stream_close_send(*stream_id).unwrap();
43-
}
44-
exchange_packets(client, server, false);
45-
}
46-
47-
fn connect() -> (Http3Client, Http3Server) {
48-
let cp = ConnectionParameters::default()
49-
.max_streams(STREAM_TYPE, STREAMS_MAX)
50-
.pmtud(false)
51-
.pacing(false)
52-
.mlkem(false)
53-
.sni_slicing(false);
54-
let h3p = Http3Parameters::default().connection_parameters(cp);
55-
let mut client = http3_client_with_params(h3p.clone());
56-
let mut server = http3_server_with_params(h3p);
57-
exchange_packets(&mut client, &mut server, true);
58-
(client, server)
59-
}
21+
const ZERO: Duration = Duration::from_millis(0);
22+
const JITTER: Duration = Duration::from_millis(10);
23+
const TRANSFER_AMOUNT: usize = 1 << 22; // 4Mbyte
6024

6125
fn criterion_benchmark(c: &mut Criterion) {
6226
fixture_init();
6327

64-
for (streams, data_size) in [(1_000, 1), (1_000, 1_000)] {
65-
let mut group = c.benchmark_group(format!("{streams} streams of {data_size} bytes"));
66-
67-
// High variance benchmark. Increase default sample size (100).
68-
group.sample_size(500);
69-
70-
group.bench_function("multistream", |b| {
71-
let data = vec![0; data_size];
72-
b.iter_batched_ref(
73-
connect,
74-
|_| black_box(|(client, server)| use_streams(client, server, streams, &data)),
75-
BatchSize::SmallInput,
76-
);
28+
let mut group = c.benchmark_group(" TODO");
29+
group.throughput(Throughput::Bytes(TRANSFER_AMOUNT as u64));
30+
31+
for (streams, data_size) in [(1, 1_000) /* (1_000, 1), (1_000, 1_000) */] {
32+
group.bench_function(&format!("{streams} streams of {data_size} bytes"), |b| {
33+
b.iter_custom(|iters| {
34+
let mut d_sum = Duration::ZERO;
35+
for _i in 0..iters {
36+
let nodes = boxed![
37+
Node::default_client(boxed![Request::new(TRANSFER_AMOUNT)]),
38+
RandomDelay::new(ZERO..JITTER),
39+
Node::default_server(boxed![Response::new(TRANSFER_AMOUNT)]),
40+
RandomDelay::new(ZERO..JITTER),
41+
];
42+
let sim = Simulator::new("", nodes);
43+
d_sum += black_box(sim.setup().run());
44+
}
45+
46+
d_sum
47+
});
7748
});
78-
group.finish();
7949
}
50+
51+
group.finish();
52+
53+
Criterion::default().configure_from_args().final_summary();
8054
}
8155

8256
criterion_group!(benches, criterion_benchmark);

0 commit comments

Comments
 (0)