|
| 1 | +//! Benchmarks for bundle simulation: varying counts, DB latency, and concurrency. |
| 2 | +
|
| 3 | +use crate::fixture::{Fixture, LATENCIES, set_up_bundle_sim, set_up_sender_distribution_sim}; |
| 4 | +use builder::test_utils::setup_test_config; |
| 5 | +use criterion::{BatchSize, Bencher, BenchmarkId, Criterion}; |
| 6 | +use std::time::Duration; |
| 7 | + |
| 8 | +pub fn bench_bundle_counts(criterion: &mut Criterion) { |
| 9 | + const LATENCY: Duration = Duration::ZERO; |
| 10 | + const CONCURRENCY: usize = 4; |
| 11 | + |
| 12 | + setup_test_config(); |
| 13 | + let runtime = tokio::runtime::Runtime::new().unwrap(); |
| 14 | + |
| 15 | + let mut group = criterion.benchmark_group("sim_varying_simple_bundle_counts_no_db_latency"); |
| 16 | + group.sample_size(10); |
| 17 | + |
| 18 | + for bundle_count in [1, 10, 100, 1000] { |
| 19 | + group.bench_with_input( |
| 20 | + BenchmarkId::new("bundle_count", bundle_count), |
| 21 | + &bundle_count, |
| 22 | + |bench: &mut Bencher, &bundle_count| { |
| 23 | + bench.to_async(&runtime).iter_batched( |
| 24 | + || set_up_bundle_sim(bundle_count, LATENCY, CONCURRENCY), |
| 25 | + Fixture::run, |
| 26 | + BatchSize::PerIteration, |
| 27 | + ); |
| 28 | + }, |
| 29 | + ); |
| 30 | + } |
| 31 | + group.finish(); |
| 32 | +} |
| 33 | + |
| 34 | +pub fn bench_bundle_db_latency(criterion: &mut Criterion) { |
| 35 | + const BUNDLE_COUNT: usize = 10; |
| 36 | + const CONCURRENCY: usize = 4; |
| 37 | + |
| 38 | + setup_test_config(); |
| 39 | + let runtime = tokio::runtime::Runtime::new().unwrap(); |
| 40 | + |
| 41 | + let mut group = |
| 42 | + criterion.benchmark_group(format!("sim_{BUNDLE_COUNT}_simple_bundles_varying_db_latency")); |
| 43 | + group.sample_size(10); |
| 44 | + |
| 45 | + for (label, latency) in LATENCIES { |
| 46 | + group.bench_with_input(BenchmarkId::new("latency", label), &latency, |bench, &lat| { |
| 47 | + bench.to_async(&runtime).iter_batched( |
| 48 | + || set_up_bundle_sim(BUNDLE_COUNT, lat, CONCURRENCY), |
| 49 | + Fixture::run, |
| 50 | + BatchSize::PerIteration, |
| 51 | + ); |
| 52 | + }); |
| 53 | + } |
| 54 | + group.finish(); |
| 55 | +} |
| 56 | + |
| 57 | +pub fn bench_bundle_concurrency(criterion: &mut Criterion) { |
| 58 | + const BUNDLE_COUNT: usize = 100; |
| 59 | + const LATENCY: Duration = Duration::ZERO; |
| 60 | + |
| 61 | + setup_test_config(); |
| 62 | + let runtime = tokio::runtime::Runtime::new().unwrap(); |
| 63 | + |
| 64 | + let mut group = criterion.benchmark_group(format!( |
| 65 | + "sim_{BUNDLE_COUNT}_simple_bundles_no_db_latency_varying_concurrency" |
| 66 | + )); |
| 67 | + group.sample_size(10); |
| 68 | + |
| 69 | + for concurrency in [1, 2, 4, 8, 16] { |
| 70 | + group.bench_with_input( |
| 71 | + BenchmarkId::new("thread_count", concurrency), |
| 72 | + &concurrency, |
| 73 | + |bench, &conc| { |
| 74 | + bench.to_async(&runtime).iter_batched( |
| 75 | + || set_up_bundle_sim(BUNDLE_COUNT, LATENCY, conc), |
| 76 | + Fixture::run, |
| 77 | + BatchSize::PerIteration, |
| 78 | + ); |
| 79 | + }, |
| 80 | + ); |
| 81 | + } |
| 82 | + group.finish(); |
| 83 | +} |
| 84 | + |
| 85 | +pub fn bench_bundle_sender_distribution(criterion: &mut Criterion) { |
| 86 | + const BUNDLE_COUNT: usize = 100; |
| 87 | + const CONCURRENCY: usize = 4; |
| 88 | + |
| 89 | + setup_test_config(); |
| 90 | + let runtime = tokio::runtime::Runtime::new().unwrap(); |
| 91 | + |
| 92 | + let mut group = criterion.benchmark_group(format!( |
| 93 | + "sim_{BUNDLE_COUNT}_simple_bundles_no_db_latency_varying_sender_count" |
| 94 | + )); |
| 95 | + group.sample_size(10); |
| 96 | + |
| 97 | + for num_senders in [1, 5, 20, 100] { |
| 98 | + group.bench_with_input( |
| 99 | + BenchmarkId::new("sender_count", num_senders), |
| 100 | + &num_senders, |
| 101 | + |bench, &senders| { |
| 102 | + bench.to_async(&runtime).iter_batched( |
| 103 | + || set_up_sender_distribution_sim(BUNDLE_COUNT, senders, CONCURRENCY), |
| 104 | + Fixture::run, |
| 105 | + BatchSize::PerIteration, |
| 106 | + ); |
| 107 | + }, |
| 108 | + ); |
| 109 | + } |
| 110 | + group.finish(); |
| 111 | +} |
0 commit comments