Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Benchmarking HakoDB

The official harnesses live in hakodb/hakobench. Run them locally against a core checkout or a release asset. Two rules matter: settle background work before measuring, and compare equal work.

Build (Windows, MinGW)

HAKODB_DIR points at a core checkout (default ../hakodb). -I takes the core’s release directory because the core’s build generates hakodb.h next to the binaries when built with the header feature (cargo build --release --features header; plain builds skip header generation).

$env:HAKODB_DIR = "<core-checkout>"
g++.exe -O2 -std=c++17 `
  -I$env:HAKODB_DIR\target\release benchmark.cpp `
  -L$env:HAKODB_DIR\target\release -lhakodb -o benchmark.exe

MinGW links directly against hakodb.dll; no import-lib step is needed.

Build (Windows, MSVC)

rustc names the cdylib import library hakodb.dll.lib (not hakodb.lib). The repo includes build-msvc.bat, which assumes VS2022 Community and a core release build side by side:

call "<VS install>\VC\Auxiliary\Build\vcvars64.bat"
cl /O2 /std:c++17 /EHsc /I %HAKODB_DIR%\target\release benchmark.cpp ^
  /link /LIBPATH:%HAKODB_DIR%\target\release hakodb.dll.lib /OUT:benchmark-msvc.exe

At runtime hakodb.dll must sit next to the exe or on PATH. Release assets rename the import lib to hakodb.lib; either name links the same way.

Build (Linux)

g++ -O2 -std=c++17 -I$HAKODB_DIR/target/release benchmark.cpp \
  -L$HAKODB_DIR/target/release -Wl,-rpath,'$ORIGIN' -lhakodb -o benchmark

sqlite_bench.cpp needs a local sqlite3 development library.

Run

./benchmark --docs=1000          # full matrix
./benchmark --docs=1000 --gate   # regression gate (Manual profile)
./benchmark --docs=10000         # larger dataset
./benchmark --profile=Always --wstats
./benchmark --index-groups=std,f2f6 --profile=Manual
./benchmark --index-groups=all --profile=Manual
./benchmark --profile=Segment --docs=1000

Use --docs >= 1000 for meaningful results. Each run creates and destroys temporary bench_data_* directories; existing databases are not touched. A full --docs=10000 run takes several minutes because durable profiles fsync per write and the Gaming profile moves about 500 MB.

What it measures

MetricDescription
WPS (Sgl/Btc)Single writes/sec and batch writes/sec
RPS (Seq/Par)Sequential and multi-threaded point-reads/sec
STRESS (Get/Qry/Cmp/Reuse/Comp/Range)Point-get, indexed query, composite prefix query, pooled-handle query, composite-prefix + range, and range-bound query throughput
QPS (Off/Cur)Offset-pagination and cursor-pagination queries/sec
Agg QPSAggregate queries/sec (sum)
Tx WPSSerializable transactions/sec
Bulk Upd/DelBulk update and bulk delete ops/sec
Scan (Fwd/Rev)Full-table decoded scans in both directions, docs/s
ScanRaw / ScanKeyByte/key-only full scans, docs/s
Startup/FlushEngine open (ms) and clean shutdown (ms)
SizeOn-disk database size

Profiles: Always, Interval, Manual, OnCommit, Enc_Comp (encrypted + compressed), and Gaming (large documents, parallel workers). Segment is a diagnostic profile (0 inline budget, 1 MB rotation) that spills WAL-inlined docs into segments and reports the segment/WAL inventory plus a timed compact().

Compare equal execution lanes

The harness times the native query executor (hk_query_execute_to_handles), which returns handles without per-document JSON. An SDK call that serializes rows to JSON and parses them into language objects measures the SDK and the egress layer, not the same lane. When comparing harnesses, use the handle or view path on both sides, or explicitly label the JSON path as an integration cost. The same rule applies to the two JSON executors: they produce the same output but take different materialization paths.

The EXTENDED section covers additional index families. Select them with --index-groups (default std):

GroupIndexes
stdSecondary indexes (active, tenant, id, age) and plain composites ([id], [tenant,score])
f2f6Unique (uniqbench.slug), dotted ([profile.city]), and covering ([tenant,active]) indexes
vectorVector index on bench.emb (32-dim), plus a kNN lane
graphEdge index on a 200-node/200-edge graph, plus BFS and edge-write lanes

Settle first

A freshly written database is not a settled one. Four background stages run asynchronously: open-time index recovery, async index updates, blob persistence, and periodic maintenance (checkpoint/compaction/snapshots). Reads issued during that work measure contention, not the settled database.

#![allow(unused)]
fn main() {
// After fill, before every measured stage:
assert!(db.await_quiescent(Duration::from_secs(30)));

// Inspect what is still outstanding:
let s = db.quiescence_status();
// indexes_ready, pending_index_ops, index_backfills, pending_blob_bytes,
// queued_blob_items, maintenance_running — plus is_quiescent()
}

FFI: hk_engine_await_quiescent(db, 30000) and hk_engine_quiescence_status(db) (JSON; free with hk_string_free). is_indexes_ready() covers only the first of the four stages.

Compare equal work

ShapeHakoDB opFair comparisonNotes
Owned full scandecoded keyset pagesSELECT * + owned per-row copiesCopy documents on both sides
Byte scanwalk / hk_cursor_walkcursor + key movementNo decode on either side
Lazy (few fields)walk_view + pullsnarrow SELECT + accessor touchesSame fields, same count
Point fieldviewGet + typed getterraw value fetchNo JSON on either side
JSON servehk_result_set_to_jsonjson_group_array(json_object(…))Verify binary handling matches
Deep pageskeyset start_after at depth DOFFSET D LIMIT 20Compares seek cost with skip cost

Use the same document count, payload shape, field count, and durability mode on both sides. Run each shape at least three times and report the median; do not compare a cold run with a warm one. State whether the numbers are cold or warm.

Official tools

  • benchmark.cpp — reference harness over the C ABI. Profiles across durability and workload mixes; --gate runs the median-of-3 regression gate on the Manual profile.
  • sqlite_bench.cpp — SQLite mirror with the same stages, loop counts, math, and table geometry.