You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Revise design documentation for high-performance caches
- Updated terminology to reflect broader application beyond DBMS, emphasizing the importance of workload modeling and memory layout.
- Clarified access patterns and cache policies, including roadmap mentions for LRU-K, 2Q, and ARC.
- Enhanced sections on concurrency strategy, eviction paths, and scan resistance, aligning with performance goals and design principles.
- Improved overall readability and consistency throughout the document.
Copy file name to clipboardExpand all lines: docs/design.md
+21-21Lines changed: 21 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
-
Designing high-performance caches for a DBMS in Rust is a multi-disciplinary problem: data structures, memory layout, concurrency, workload modeling, and systems-level performance all matter. The points below reflect what moves the needle in practice.
1
+
Designing high-performance caches in Rust is a multi-disciplinary problem: data structures, memory layout, concurrency, workload modeling, and systems-level performance all matter. The points below reflect what moves the needle in practice across systems, services, and libraries.
2
2
3
3
## 1. Workload First, Policy Second
4
4
5
5
Cache policy only matters relative to workload.
6
6
7
7
Identify access patterns:
8
-
-OLTP: skewed, hot keys, high churn.
9
-
-OLAP: scans, large working sets, weak locality.
10
-
- Mixed: bursts of hot data over large cold sets.
8
+
-Hotset-heavy traffic: skewed keys, high churn.
9
+
-Scan-heavy traffic: large working sets, weak locality.
10
+
- Mixed traffic: bursts of hot data over large cold sets.
11
11
12
12
Measure:
13
13
- Reuse distance / stack distance.
@@ -16,14 +16,14 @@ Measure:
16
16
17
17
Choose policies accordingly:
18
18
- LRU: good for temporal locality, bad for scans.
19
-
- LRU-K / 2Q: better at filtering one-off accesses.
20
-
- Clock / ARC: lower overhead, more adaptive.
19
+
- LRU-K / 2Q (roadmap): better at filtering one-off accesses.
20
+
- Clock / ARC (roadmap): lower overhead, more adaptive.
21
21
22
-
Never design a "general purpose" cache first, design for the workload you expect.
22
+
Never design a "general purpose" cache first; design for the workload you expect.
23
23
24
24
## 2. Memory Layout Matters More Than Algorithms
25
25
26
-
In a DBMS cache, memory layout often dominates policy.
26
+
In a cache, memory layout often dominates policy.
27
27
28
28
Prefer:
29
29
- Contiguous storage (Vec, slabs, arenas).
@@ -38,7 +38,7 @@ Techniques:
38
38
- Separate hot metadata from cold payloads.
39
39
- Use slab allocators for fixed-size entries.
40
40
41
-
Cache misses caused by your own data structure are as bad as disk misses.
41
+
Cache misses caused by your own data structure are as bad as upstream misses.
42
42
43
43
## 3. Concurrency Strategy Is Core Design, Not a Wrapper
44
44
@@ -50,7 +50,7 @@ Options:
50
50
- Lock-free or mostly-lock-free: hard in Rust, only worth it if contention dominates.
51
51
52
52
Rust-specific notes:
53
-
-Prefer parking_lot locks over std.
53
+
-When `std` is available, prefer `parking_lot` locks over `std::sync` for lower overhead and better ergonomics.
54
54
- Avoid Arc<Mutex<...>> in hot paths.
55
55
- Consider per-thread caches with periodic merge.
56
56
- Consider RCU-style read paths for read-heavy caches.
@@ -80,9 +80,9 @@ If malloc shows up in your flamegraph, your cache is already slow.
80
80
81
81
Eviction is the critical slow path.
82
82
83
-
O(1) eviction is mandatory.
83
+
O(1) eviction is the goal.
84
84
85
-
No tree walks, no scanning.
85
+
Avoid unbounded tree walks or scans in eviction paths.
86
86
87
87
Maintain:
88
88
- Direct pointers/indices to eviction candidates.
@@ -103,7 +103,7 @@ Track at least:
103
103
- Eviction count and reason.
104
104
- Insert/update rate.
105
105
- Scan pollution rate.
106
-
- Lock contention or wait time.
106
+
- Lock contention or wait time (roadmap).
107
107
108
108
Expose:
109
109
- Lightweight counters in hot path.
@@ -115,8 +115,8 @@ Metrics should guide design decisions, not justify them afterward.
115
115
116
116
Design in layers:
117
117
- Storage layer: how entries live in memory, allocation, layout, indexing.
118
-
- Policy layer: LRU, FIFO, Clock, ARC, etc; only manipulates metadata and ordering.
119
-
- Integration layer: ties DB pages, tuples, or segments into cache entries.
118
+
- Policy layer: LRU, FIFO, LFU, LRU-K (roadmap: Clock/ARC/2Q, etc; see `docs/policies/roadmap/README.md`); only manipulates metadata and ordering.
119
+
- Integration layer: ties application objects, payloads, or IDs into cache entries.
120
120
121
121
Related docs:
122
122
- Policy summaries: `docs/policies.md`
@@ -147,18 +147,18 @@ You can wrap fast internals in nice APIs at the edges.
147
147
148
148
## 9. Scans Are the Enemy of Caches
149
149
150
-
In DBMS workloads:
150
+
In scan-heavy workloads:
151
151
152
-
Large table scans destroy LRU-style caches.
152
+
Large sequential reads destroy LRU-style caches.
153
153
154
154
Solutions:
155
-
- Scan-resistant policies (2Q, LRU-K, ARC).
156
-
- Explicit "scan mode" hints from query planner.
155
+
- Scan-resistant policies (LRU-K, 2Q/ARC are roadmap).
156
+
- Explicit "scan mode" hints from the caller or workload layer.
157
157
- Bypass cache for known one-shot reads.
158
158
159
159
If you ignore scans, your cache will look great in microbenchmarks and terrible in production.
160
160
161
-
## 10. Benchmark Like a Database, Not a Library
161
+
## 10. Benchmark Like a System, Not a Library
162
162
163
163
Do not rely on random key benchmarks.
164
164
@@ -207,7 +207,7 @@ A cache that collapses under stress is worse than no cache.
207
207
208
208
## Bottom Line
209
209
210
-
High-performance DBMS caches are not about clever algorithms—they are about:
210
+
High-performance caches are not about clever algorithms—they are about:
0 commit comments