Running benchmarks

How to measure skaidb on your own hardware, with your own workload, so that the numbers mean something. This page publishes no results: a figure is only worth what its environment, durability settings and client are, and those are yours.

What to decide first

The question. "How many transactions per second at 16 connections on this disk" and "does this setting help my read mix" are different runs. Write the question down before the first run; it decides the workload, the connection count and how long to run.

The durability you are measuring. Every acknowledged write in skaidb is durable (a disk flush) before the client is told, on every replica that counts toward the write's consistency level. A write benchmark is therefore mostly a measurement of the disk's flush rate and of how many writers share one flush. Measure that rate first — a loop that appends a few kilobytes to a file and calls fdatasync, timed — because it is the ceiling for a single connection, and because consumer SSDs can drop to a fraction of their rate for tens of seconds after heavy writes. Check it again before each write run.

The topology. A standalone server, or a cluster with its replication factor and consistency levels. On a cluster a write waits for the replicas its consistency level names, so the network round trip between members is part of every write; see Cluster consistency.

The data size. Load the table to the size you will run in production, or at least well past what fits in the memtable and the read cache (storage.memtable_size_mb, storage.read_cache_entries). A table that lives entirely in memory answers a different question.

A load generator: pgbench over the PostgreSQL port

skaidb speaks the PostgreSQL wire protocol on its own port (see PostgreSQL protocol), so pgbench — shipped with every PostgreSQL client package — drives it with custom scripts. Enable the listener:

[postgres]
enabled = true
port = 5432

pgbench's built-in scripts and its -i initialisation use PostgreSQL catalog features, so create the tables yourself and pass -n (no vacuum) with a script file:

CREATE TABLE accounts (PRIMARY KEY (aid));
CREATE INDEX accounts_owner ON accounts (owner);
CREATE TABLE history (PRIMARY KEY (hid));

Load rows with COPY (or \copy from psql), then run a script:

export PGPASSWORD=...
pgbench -h 127.0.0.1 -p 5432 -U admin -n -M prepared \
        -f update.sql -c 16 -j 4 -T 60 -r bench
  • -M prepared uses the extended protocol with prepared statements, as an application's driver does.
  • -c is the number of connections, -j the client threads driving them. Raise -j with -c, and make sure the machine running pgbench is not the bottleneck (watch its CPU).
  • -r prints the latency of each statement of the script, which is how you find where a transaction's time goes.
  • -T at least 30–60 seconds for a figure you will quote; the first run after a start is a warm-up and is discarded.
  • A script that can collide with itself (two connections updating one row inside transactions) should also pass --max-tries, and you should read the "retried" and "failed" lines of the report.

Applications that use the native drivers can of course be measured with their own code: one persistent connection per client thread, connections opened before the timed window.

Workloads

Write the scripts that look like your application. As a starting set, each in its own file, with \set drawing keys at random:

-- sel.sql: a read by primary key
\set aid random(1, 1000000)
SELECT abalance FROM accounts WHERE aid = :aid;
-- idx.sql: a read through a secondary index
\set owner random(1, 100000)
SELECT aid FROM accounts WHERE owner = :owner;
-- upd.sql: one update, acknowledged when durable
\set aid random(1, 1000000)
\set delta random(-5000, 5000)
UPDATE accounts SET abalance = abalance + :delta WHERE aid = :aid;
-- txn.sql: a transaction of two statements
\set hid random(1, 9000000000000000)
\set aid random(1, 1000000)
\set delta random(-5000, 5000)
BEGIN;
UPDATE accounts SET abalance = abalance + :delta WHERE aid = :aid;
INSERT INTO history (hid, aid, delta, mtime) VALUES (:hid::bigint, :aid::bigint, :delta::int, now());
END;

Run each at 1 connection and at the connection counts you expect. One connection shows the cost of a single statement; many show how the server shares the disk and its cores among writers.

Transactions (BEGIN … COMMIT) run on a standalone server; a cluster takes each statement on its own (see Transactions).

What to hold constant

  • The client's place. Run the load generator on the same network segment as the server, or on the server itself over loopback, and say which. A client a routed hop away measures the network: at one connection the round trip is the whole result.
  • One system at a time on the machine and the disk. Anything else writing to the same disk shares its flush rate.
  • Connections opened before the clock starts. Authentication is a deliberate cost and is not part of a statement's latency.
  • The same settings from run to run: storage.memory_target, consistency levels, at-rest encryption, TLS. Record the configuration file with the result.
  • A settled server. After a bulk load, wait for the flush and merge work it left to finish before timing reads (watch skaidb_storage_compactions_total stop moving).
  • The first run discarded. A server just started reads low for one run.

What to record

From the load generator: throughput, the latency average and — more useful — a high percentile, per statement where the tool gives it.

From the server's metrics endpoint (Metrics), read before and after the run:

  • skaidb_wal_fsyncs_total — disk flushes issued. Throughput divided by the flush rate is how many writes shared each flush.
  • skaidb_txn_commits_settled_total and skaidb_txn_commit_settle_rounds_total — transaction commits and the rounds of log syncs that settled them.
  • skaidb_cache_hits_total / skaidb_cache_misses_total — whether the read workload is served from memory or from disk.
  • skaidb_slow_queries_total and the slow log — statements over observability.slow_query_ms.
  • The process's CPU time (from the operating system): how many cores the run used tells you whether you were bound by the disk or by CPU.

Record the hardware (CPU, memory, the disk model and its measured flush rate), the skaidb version, and the data size with every figure.

Comparing two builds or two settings

A difference between two runs is evidence only if it is larger than the spread between two runs of the same thing. Measure that spread first: run one configuration five times and look at the range.

  • Interleave. Run A, B, A, B, … rather than all of A and then all of B: machines drift (thermal state, background work, the disk's state), and drift between blocks looks like a difference.
  • Alternate which goes first in each pair, and compare medians. The first run of a pair tends to read low in whichever order the pair runs.
  • Repeat at another time. Legs that agree hours apart are worth more than many runs inside one window.
  • Use one copy of the data for both sides where the comparison allows it: copy the data directory once and start each build on its own copy, so both read tables of the same shape.

Reading the result

  • One connection on a write workload reads close to the disk's flush rate: each acknowledged write is a flush. If it reads far below, look at what else each statement does (indexes maintained, constraints checked).
  • Many connections should exceed the flush rate several times over: writers that arrive together share a flush. If throughput stops rising with connections while the disk is not saturated and several cores are idle, the limit is in the server; if the disk's flush counter is at its measured rate, the limit is the disk.
  • Reads scale with cores until the working set no longer fits in memory; from there the disk's read latency decides.
  • A number without its environment is not a result. Quote the hardware, the durability, the client's place and the data size beside it.
Search the docs