|
1 | 1 | //! Quantify a single walredo manager's throughput under N concurrent callers.
|
2 | 2 | //!
|
3 | 3 | //! The benchmark implementation ([`bench_impl`]) is parametrized by
|
4 |
| -//! - `redo_work` => [`Request::short_request`] or [`Request::medium_request`] |
| 4 | +//! - `redo_work` => an async closure that takes a `PostgresRedoManager` and performs one redo |
5 | 5 | //! - `n_redos` => number of times the benchmark shell execute the `redo_work`
|
6 | 6 | //! - `nclients` => number of clients (more on this shortly).
|
7 | 7 | //!
|
|
10 | 10 | //! Each task executes the `redo_work` `n_redos/nclients` times.
|
11 | 11 | //!
|
12 | 12 | //! We exercise the following combinations:
|
13 |
| -//! - `redo_work = short / medium`` |
| 13 | +//! - `redo_work = ping / short / medium`` |
14 | 14 | //! - `nclients = [1, 2, 4, 8, 16, 32, 64, 128]`
|
15 | 15 | //!
|
16 | 16 | //! We let `criterion` determine the `n_redos` using `iter_custom`.
|
|
27 | 27 | //!
|
28 | 28 | //! # Reference Numbers
|
29 | 29 | //!
|
30 |
| -//! 2024-04-15 on i3en.3xlarge |
| 30 | +//! 2024-09-18 on im4gn.2xlarge |
31 | 31 | //!
|
32 | 32 | //! ```text
|
33 |
| -//! short/1 time: [24.584 µs 24.737 µs 24.922 µs] |
34 |
| -//! short/2 time: [33.479 µs 33.660 µs 33.888 µs] |
35 |
| -//! short/4 time: [42.713 µs 43.046 µs 43.440 µs] |
36 |
| -//! short/8 time: [71.814 µs 72.478 µs 73.240 µs] |
37 |
| -//! short/16 time: [132.73 µs 134.45 µs 136.22 µs] |
38 |
| -//! short/32 time: [258.31 µs 260.73 µs 263.27 µs] |
39 |
| -//! short/64 time: [511.61 µs 514.44 µs 517.51 µs] |
40 |
| -//! short/128 time: [992.64 µs 998.23 µs 1.0042 ms] |
41 |
| -//! medium/1 time: [110.11 µs 110.50 µs 110.96 µs] |
42 |
| -//! medium/2 time: [153.06 µs 153.85 µs 154.99 µs] |
43 |
| -//! medium/4 time: [317.51 µs 319.92 µs 322.85 µs] |
44 |
| -//! medium/8 time: [638.30 µs 644.68 µs 652.12 µs] |
45 |
| -//! medium/16 time: [1.2651 ms 1.2773 ms 1.2914 ms] |
46 |
| -//! medium/32 time: [2.5117 ms 2.5410 ms 2.5720 ms] |
47 |
| -//! medium/64 time: [4.8088 ms 4.8555 ms 4.9047 ms] |
48 |
| -//! medium/128 time: [8.8311 ms 8.9849 ms 9.1263 ms] |
| 33 | +//! ping/1 time: [21.789 µs 21.918 µs 22.078 µs] |
| 34 | +//! ping/2 time: [27.686 µs 27.812 µs 27.970 µs] |
| 35 | +//! ping/4 time: [35.468 µs 35.671 µs 35.926 µs] |
| 36 | +//! ping/8 time: [59.682 µs 59.987 µs 60.363 µs] |
| 37 | +//! ping/16 time: [101.79 µs 102.37 µs 103.08 µs] |
| 38 | +//! ping/32 time: [184.18 µs 185.15 µs 186.36 µs] |
| 39 | +//! ping/64 time: [349.86 µs 351.45 µs 353.47 µs] |
| 40 | +//! ping/128 time: [684.53 µs 687.98 µs 692.17 µs] |
| 41 | +//! short/1 time: [31.833 µs 32.126 µs 32.428 µs] |
| 42 | +//! short/2 time: [35.558 µs 35.756 µs 35.992 µs] |
| 43 | +//! short/4 time: [44.850 µs 45.138 µs 45.484 µs] |
| 44 | +//! short/8 time: [65.985 µs 66.379 µs 66.853 µs] |
| 45 | +//! short/16 time: [127.06 µs 127.90 µs 128.87 µs] |
| 46 | +//! short/32 time: [252.98 µs 254.70 µs 256.73 µs] |
| 47 | +//! short/64 time: [497.13 µs 499.86 µs 503.26 µs] |
| 48 | +//! short/128 time: [987.46 µs 993.45 µs 1.0004 ms] |
| 49 | +//! medium/1 time: [137.91 µs 138.55 µs 139.35 µs] |
| 50 | +//! medium/2 time: [192.00 µs 192.91 µs 194.07 µs] |
| 51 | +//! medium/4 time: [389.62 µs 391.55 µs 394.01 µs] |
| 52 | +//! medium/8 time: [776.80 µs 780.33 µs 784.77 µs] |
| 53 | +//! medium/16 time: [1.5323 ms 1.5383 ms 1.5459 ms] |
| 54 | +//! medium/32 time: [3.0120 ms 3.0226 ms 3.0350 ms] |
| 55 | +//! medium/64 time: [5.7405 ms 5.7787 ms 5.8166 ms] |
| 56 | +//! medium/128 time: [10.412 ms 10.574 ms 10.718 ms] |
49 | 57 | //! ```
|
50 | 58 |
|
51 | 59 | use anyhow::Context;
|
52 | 60 | use bytes::{Buf, Bytes};
|
53 | 61 | use criterion::{BenchmarkId, Criterion};
|
| 62 | +use once_cell::sync::Lazy; |
54 | 63 | use pageserver::{config::PageServerConf, walrecord::NeonWalRecord, walredo::PostgresRedoManager};
|
55 | 64 | use pageserver_api::{key::Key, shard::TenantShardId};
|
56 | 65 | use std::{
|
| 66 | + future::Future, |
57 | 67 | sync::Arc,
|
58 | 68 | time::{Duration, Instant},
|
59 | 69 | };
|
60 | 70 | use tokio::{sync::Barrier, task::JoinSet};
|
61 | 71 | use utils::{id::TenantId, lsn::Lsn};
|
62 | 72 |
|
63 | 73 | fn bench(c: &mut Criterion) {
|
64 |
| - { |
65 |
| - let nclients = [1, 2, 4, 8, 16, 32, 64, 128]; |
66 |
| - for nclients in nclients { |
67 |
| - let mut group = c.benchmark_group("short"); |
68 |
| - group.bench_with_input( |
69 |
| - BenchmarkId::from_parameter(nclients), |
70 |
| - &nclients, |
71 |
| - |b, nclients| { |
72 |
| - let redo_work = Arc::new(Request::short_input()); |
73 |
| - b.iter_custom(|iters| bench_impl(Arc::clone(&redo_work), iters, *nclients)); |
74 |
| - }, |
75 |
| - ); |
76 |
| - } |
77 |
| - } |
78 |
| - { |
79 |
| - let nclients = [1, 2, 4, 8, 16, 32, 64, 128]; |
80 |
| - for nclients in nclients { |
81 |
| - let mut group = c.benchmark_group("medium"); |
82 |
| - group.bench_with_input( |
83 |
| - BenchmarkId::from_parameter(nclients), |
84 |
| - &nclients, |
85 |
| - |b, nclients| { |
86 |
| - let redo_work = Arc::new(Request::medium_input()); |
87 |
| - b.iter_custom(|iters| bench_impl(Arc::clone(&redo_work), iters, *nclients)); |
88 |
| - }, |
89 |
| - ); |
90 |
| - } |
| 74 | + macro_rules! bench_group { |
| 75 | + ($name:expr, $redo_work:expr) => {{ |
| 76 | + let name: &str = $name; |
| 77 | + let nclients = [1, 2, 4, 8, 16, 32, 64, 128]; |
| 78 | + for nclients in nclients { |
| 79 | + let mut group = c.benchmark_group(name); |
| 80 | + group.bench_with_input( |
| 81 | + BenchmarkId::from_parameter(nclients), |
| 82 | + &nclients, |
| 83 | + |b, nclients| { |
| 84 | + b.iter_custom(|iters| bench_impl($redo_work, iters, *nclients)); |
| 85 | + }, |
| 86 | + ); |
| 87 | + } |
| 88 | + }}; |
91 | 89 | }
|
| 90 | + // |
| 91 | + // benchmark the protocol implementation |
| 92 | + // |
| 93 | + let pg_version = 14; |
| 94 | + bench_group!( |
| 95 | + "ping", |
| 96 | + Arc::new(move |mgr: Arc<PostgresRedoManager>| async move { |
| 97 | + let _: () = mgr.ping(pg_version).await.unwrap(); |
| 98 | + }) |
| 99 | + ); |
| 100 | + // |
| 101 | + // benchmarks with actual record redo |
| 102 | + // |
| 103 | + let make_redo_work = |req: &'static Request| { |
| 104 | + Arc::new(move |mgr: Arc<PostgresRedoManager>| async move { |
| 105 | + let page = req.execute(&mgr).await.unwrap(); |
| 106 | + assert_eq!(page.remaining(), 8192); |
| 107 | + }) |
| 108 | + }; |
| 109 | + bench_group!("short", { |
| 110 | + static REQUEST: Lazy<Request> = Lazy::new(Request::short_input); |
| 111 | + make_redo_work(&REQUEST) |
| 112 | + }); |
| 113 | + bench_group!("medium", { |
| 114 | + static REQUEST: Lazy<Request> = Lazy::new(Request::medium_input); |
| 115 | + make_redo_work(&REQUEST) |
| 116 | + }); |
92 | 117 | }
|
93 | 118 | criterion::criterion_group!(benches, bench);
|
94 | 119 | criterion::criterion_main!(benches);
|
95 | 120 |
|
96 | 121 | // Returns the sum of each client's wall-clock time spent executing their share of the n_redos.
|
97 |
| -fn bench_impl(redo_work: Arc<Request>, n_redos: u64, nclients: u64) -> Duration { |
| 122 | +fn bench_impl<F, Fut>(redo_work: Arc<F>, n_redos: u64, nclients: u64) -> Duration |
| 123 | +where |
| 124 | + F: Fn(Arc<PostgresRedoManager>) -> Fut + Send + Sync + 'static, |
| 125 | + Fut: Future<Output = ()> + Send + 'static, |
| 126 | +{ |
98 | 127 | let repo_dir = camino_tempfile::tempdir_in(env!("CARGO_TARGET_TMPDIR")).unwrap();
|
99 | 128 |
|
100 | 129 | let conf = PageServerConf::dummy_conf(repo_dir.path().to_path_buf());
|
@@ -135,17 +164,20 @@ fn bench_impl(redo_work: Arc<Request>, n_redos: u64, nclients: u64) -> Duration
|
135 | 164 | })
|
136 | 165 | }
|
137 | 166 |
|
138 |
| -async fn client( |
| 167 | +async fn client<F, Fut>( |
139 | 168 | mgr: Arc<PostgresRedoManager>,
|
140 | 169 | start: Arc<Barrier>,
|
141 |
| - redo_work: Arc<Request>, |
| 170 | + redo_work: Arc<F>, |
142 | 171 | n_redos: u64,
|
143 |
| -) -> Duration { |
| 172 | +) -> Duration |
| 173 | +where |
| 174 | + F: Fn(Arc<PostgresRedoManager>) -> Fut + Send + Sync + 'static, |
| 175 | + Fut: Future<Output = ()> + Send + 'static, |
| 176 | +{ |
144 | 177 | start.wait().await;
|
145 | 178 | let start = Instant::now();
|
146 | 179 | for _ in 0..n_redos {
|
147 |
| - let page = redo_work.execute(&mgr).await.unwrap(); |
148 |
| - assert_eq!(page.remaining(), 8192); |
| 180 | + redo_work(Arc::clone(&mgr)).await; |
149 | 181 | // The real pageserver will rarely if ever do 2 walredos in a row without
|
150 | 182 | // yielding to the executor.
|
151 | 183 | tokio::task::yield_now().await;
|
|
0 commit comments