# Real-Hardware Benchmark & Verification Methodology

> Open, reproducible real-hardware verification methodology for TursoDB: fair durability parity, hoisted prepared statements, io_uring syscalls, AEGIS-256 encryption, vector quantization, DuckDB ATTACH, native Rust engines, and AgentFS.
> Canonical HTML: https://tursodb.cn/docs/labs/benchmark-methodology/
> Origin: Original Community Documentation (TursoDB.cn)
> Language: en

---
This guide documents the **open, reproducible real-hardware verification methodology** maintained by TursoDB.cn. Every benchmark published on this site is generated directly from real Linux hardware runs using open scripts—never synthetic estimates—and includes an automatic CPU, kernel, and runtime fingerprint.

## Fair Verification Principles

To eliminate common database benchmarking biases, our suite enforces six strict rules across every scenario:

1. **Verified Durability Parity**: Both TursoDB and SQLite explicitly execute and read back `PRAGMA synchronous = FULL` (verified value `2`) when comparing durable write throughput, preventing asymmetric deferred-fsync comparisons.
2. **Hoisted Prepared Statements**: Every engine (TursoDB, `better-sqlite3`, `bun:sqlite`, PostgreSQL named prepared statements, DuckDB, `rusqlite`, and Stoolap) prepares SQL statements outside timed hot loops.
3. **Warm-Up & Median Reporting**: Read/decrypt scans and OLAP aggregations run dedicated warm-up passes followed by multi-round medians; concurrent write timers measure pure execution windows (excluding connection teardown and IPC overhead).
4. **Full File & WAL Accounting**: Storage footprints execute `PRAGMA wal_checkpoint(TRUNCATE)` and sum `.db`, `-wal`, and `-shm` sidecar files so compressed formats never under-report uncheckpointed data.
5. **Integrity & Row-Count Assertions**: Every write test verifies exact final row counts and zero failed operations; every native lookup verifies returned row values; encryption tests verify zero plaintext bytes on disk and keyless open rejection.
6. **Zero-FFI Native Baseline**: Alongside Node.js and Bun bindings, we run a native Rust `--release` harness comparing TursoDB, C SQLite (`rusqlite` bundled), and Stoolap with zero JavaScript/N-API overhead.

## Reference Linux Test Environment

To keep kernel, CPU crypto extensions, and storage behavior transparent and reproducible on any Linux bare-metal server or KVM virtual machine:

- **OS & Kernel**: Ubuntu 24.04 LTS or Debian 12 with Linux kernel `>= 6.8`
- **CPU**: Host passthrough exposing `aes` / `avx2` (required for accurate `AEGIS-256` and `AES-256-GCM` hardware-accelerated page encryption measurements)
- **Storage**: Local NVMe / VirtIO-SCSI disk with `io_uring` support (`ext4` or `xfs`)
- **Open File Descriptors**: `ulimit -n 65536` (allows holding 1,000+ isolated multi-tenant DB handles cleanly)

## Pre-Flight Environment Probe

Before recording numbers, verify hardware capabilities and confirm whether the kernel permits `io_uring_setup`:

```bash
# 1. Inspect kernel, virtualization, and CPU AES-NI / AVX2 flags
uname -a
systemd-detect-virt
grep -m1 -oE 'aes|avx2' /proc/cpuinfo | sort -u

# 2. Run the bundled hardware & real io_uring syscall probe
bash benchmarks/env-probe.sh
```

> **Container `io_uring` Note**: Unprivileged Linux containers often block `io_uring_setup` with `EPERM` via default `seccomp` policies. `env-probe.sh` executes a real `io_uring_setup` syscall rather than guessing from the kernel version string, recording the verified runtime capability directly in the report.

## The 8 Reproducible Scenarios (`E1`–`E8`)

All scripts live in the repository's `benchmarks/` directory and support **Node.js**, **Bun**, **Rust**, and **Shell**:

| ID | Scenario | Primary Engines & Runtimes | Key Verified Metrics |
| :--- | :--- | :--- | :--- |
| **E1** | Concurrent Write Throughput | TursoDB (`MVCC` + `BEGIN CONCURRENT`) vs `better-sqlite3` & `bun:sqlite` (`WAL` + `FULL`) | 16-worker multi-step TX TPS, 1–16w durable append TPS, p99 latency, retry/busy rate |
| **E2** | Linux I/O Stack: `io_uring` & `fsync` | Real `io_uring_setup` probe + `fio` (`io_uring` qd=1/8 vs `psync` qd=1) | Syscall status, 4 KiB WAL `fsync` p50/p95/p99, decoupled random-write + fsync IOPS |
| **E3** | Database-per-Agent Density | TursoDB (1,000 isolated `.db` files, warm cache & fresh open) vs PostgreSQL 16 (`max=50` named prepared pool) | Provisioning time/DB, active RSS memory, disk footprint, 50-concurrency read p99 |
| **E4** | Native Page Encryption Overhead | Plaintext vs `AEGIS-256` vs `AES-256-GCM` (~22 MB DB, 5-round median) | Internal engine write & fresh-open decrypt scan delta %, zero disk plaintext leak, keyless open rejection |
| **E5** | Native Vector Precision Trade-offs | `vector32` vs `vector8` vs `vector1bit` (10k × 384d clustered unit-normalized) | WAL-checkpointed storage compression ratio, cosine Top-10 p50/p99, Recall@10 |
| **E6** | OLTP + OLAP Hybrid (`ATTACH`) | TursoDB vs DuckDB (prepared OLTP + WAL-checkpointed zero-copy `ATTACH`) | Prepared single-row OLTP ops/s, 100k-row OLAP median ms, verified zero-copy `ATTACH` |
| **E7** | Native Rust Zero-FFI Comparison | TursoDB 0.8.4 vs C SQLite (`rusqlite` bundled) vs Stoolap 0.5.1 (`--release`) | 50k prepared batch insert rows/s, 2,000 verified PK lookup p50/p99, `sqlite3` CLI `integrity_check` |
| **E8** | AgentFS Sandbox Workflow | AgentFS single-file SQLite sandbox vs host directory (`cp -r` & uncompressed `tar`) | Sandbox `init`, WAL-checkpointed & restore-verified `cp` snapshot, SQL `timeline` audit |

## Running the Suite & Importing Results

```bash
# Run selected scenarios with Node.js + Bun + Rust
bash benchmarks/run-suite.sh --only e1,e4,e7 --runtime all

# Run the entire 8-scenario suite
bash benchmarks/run-suite.sh --all --runtime all

# Import a completed JSON report into the website's Benchmarks Hub
npm run benchmarks:import benchmarks/results/<report-file>.json
```

Visit the [Real-Hardware Benchmarks Hub](/benchmarks/) to inspect environment fingerprints, verified charts, and per-scenario findings.
