1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! # `Builder::tune_for(Workload::Database)` — one-line storage-engine preset
//!
//! 0.9.2 introduced workload presets to bundle the multi-knob
//! coordination that storage-engine workloads need. The `Database`
//! preset sets four knobs at once to values tuned for sustained NVMe
//! bulk-write workloads (HiveDB, embedded KV stores, LSM-tree
//! compaction):
//!
//! | Knob | Default (`Workload::Default`) | `Workload::Database` |
//! |---|---:|---:|
//! | `buffer_pool_count` | 64 | 1024 |
//! | `buffer_pool_block_size` | 4 KiB | 8 KiB |
//! | `io_uring_queue_depth` | 128 | 256 |
//! | `batch_queue_max` | 1024 | 4096 |
//!
//! Total resident memory for the pool jumps from 256 KiB to 8 MiB —
//! 32× more — to keep the dispatcher fed without per-op allocation.
//!
//! ## Apply presets first, override individual knobs second
//!
//! `tune_for(...)` mutates four fields at once. Individual setter
//! calls (`buffer_pool_count`, `io_uring_queue_depth`, etc.) override
//! the preset's value for that one knob — but calling `tune_for`
//! AFTER an individual setter overwrites the manual setting. Always
//! apply the preset first, then layer overrides.
//!
//! ## When to use this pattern
//!
//! Any storage-engine workload on NVMe: relational DBs, LSM trees,
//! KV stores, write-ahead logs. The preset is calibrated for
//! sustained sequential append + concurrent batch flush.
//!
//! ## When NOT to use this pattern
//!
//! Single-file or low-rate workloads. The 8 MiB pool footprint is
//! wasted memory for occasional file IO. `Workload::Default`
//! (= no preset) is the right baseline there.
//!
//! Run: `cargo run --example 20_tune_for_database`
use Arc;