Loading...
Loading...
How to benchmark and analyze memory usage in Turso using the memory-benchmark crate and dhat heap profiler. Use this skill whenever the user mentions memory usage, memory profiling, allocation tracking, heap analysis, memory regression, memory benchmarking, dhat, or wants to understand where memory is being allocated during SQL workloads. Also use when investigating memory growth in WAL or MVCC mode. IMPORTANT - If you modify the perf/memory crate (add profiles, change CLI flags, change output format, etc.), update this skill document to reflect those changes so it stays accurate for future agents.
npx skill4agent add tursodatabase/turso memory-benchmarkperf/memorydhatmemory-statsperf/memory/perf/memory/analyze-dhat.pydhat-heap.json# Basic: single connection, WAL mode, insert-heavy workload
cargo run --release -p memory-benchmark -- --mode wal --workload insert-heavy -i 100 -b 100
# MVCC with concurrent connections
cargo run --release -p memory-benchmark -- --mode mvcc --workload mixed -i 100 -b 100 --connections 4
# All CLI options
cargo run --release -p memory-benchmark -- \
--mode wal|mvcc \
--workload insert-heavy|read-heavy|mixed|scan-heavy \
-i <iterations> \
-b <batch-size> \
--connections <N> \
--timeout <ms> \
--cache-size <pages> \
--format human|json|csvdhat-heap.json| Profile | Description | Setup |
|---|---|---|
| 100% INSERT statements | Creates table |
| 90% SELECT by id / 10% INSERT | Seeds 10k rows |
| 50% SELECT / 50% INSERT | Seeds 10k rows |
| Full table scans with LIKE | Seeds 10k rows |
Profileperf/memory/src/profile/WorkloadProfilemain.rsmemory-statsdhat.db.db-wal.db-logdhat-heap.json# Overview: top allocation sites by bytes live at global peak
python3 perf/memory/analyze-dhat.py dhat-heap.json --top 15 --modules
# Focus on a specific subsystem
python3 perf/memory/analyze-dhat.py dhat-heap.json --filter mvcc --stacks
python3 perf/memory/analyze-dhat.py dhat-heap.json --filter btree --stacks
python3 perf/memory/analyze-dhat.py dhat-heap.json --filter page_cache --stacks
# Sort by different metrics
python3 perf/memory/analyze-dhat.py dhat-heap.json --sort-by eb # bytes at exit (leaks)
python3 perf/memory/analyze-dhat.py dhat-heap.json --sort-by tb # total bytes (pressure)
python3 perf/memory/analyze-dhat.py dhat-heap.json --sort-by mb # max live bytes per site
# JSON output for programmatic use
python3 perf/memory/analyze-dhat.py dhat-heap.json --json| Flag | Metric | Use when |
|---|---|---|
| Bytes live at global peak (default) | Finding what dominates memory at the high-water mark |
| Bytes live at exit | Finding memory leaks or things that never get freed |
| Total bytes allocated | Finding allocation pressure hotspots (GC churn) |
| Max bytes live per site | Finding per-site high-water marks |
| Total allocation count | Finding chatty allocators (many small allocs) |
--top N--filter PATTERNmvccbtreewalpager--stacks--modules--jsoncargo run -p memory-benchmark -- --mode mvcc --workload mixed -i 500 -b 100 --connections 4python3 perf/memory/analyze-dhat.py dhat-heap.json --modules --top 20turso_corepython3 perf/memory/analyze-dhat.py dhat-heap.json --filter turso_core --stacks --top 10python3 perf/memory/analyze-dhat.py dhat-heap.json --sort-by eb --top 10--connections > 1busy_timeout--timeoutBEGINBEGIN CONCURRENTProfilenext_batch(connections)perf/memory/src/profile/your_profile.rsProfilepub mod your_profile;perf/memory/src/profile/mod.rsWorkloadProfilemain.rscreate_profile()main.rsProfilepub trait Profile {
fn name(&self) -> &str;
fn next_batch(&mut self, connections: usize) -> (Phase, Vec<Vec<WorkItem>>);
}Phase::SetupPhase::RunPhase::Doneperf/memoryProfileProfile