|
6 | 6 |
|
7 | 7 | #![expect(clippy::unwrap_used, reason = "OK in a bench.")]
|
8 | 8 |
|
9 |
| -use std::{hint::black_box, iter::repeat_with}; |
| 9 | +use std::{hint::black_box, time::Duration}; |
10 | 10 |
|
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}; |
15 | 12 | 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 | + }, |
17 | 19 | };
|
18 | 20 |
|
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 |
60 | 24 |
|
61 | 25 | fn criterion_benchmark(c: &mut Criterion) {
|
62 | 26 | fixture_init();
|
63 | 27 |
|
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 | + }); |
77 | 48 | });
|
78 |
| - group.finish(); |
79 | 49 | }
|
| 50 | + |
| 51 | + group.finish(); |
| 52 | + |
| 53 | + Criterion::default().configure_from_args().final_summary(); |
80 | 54 | }
|
81 | 55 |
|
82 | 56 | criterion_group!(benches, criterion_benchmark);
|
|
0 commit comments