#!/usr/bin/env bash # Lab for "Measure honestly" # https://www.flagon.io/books/eight-kilobytes/benchmarking # # Run: ./lab 28 (from this folder; Linux, macOS, or Git Bash) # KEEP=1 ./lab 28 (leave the server up to explore; then # docker compose -f 28-benchmarking.compose.yml exec postgres bash # and docker compose -f 28-benchmarking.compose.yml down -v when done) # # Starts one PostgreSQL 18 server from 28-benchmarking.compose.yml, loads the # book's seed (about a minute and a half) and pgbench's own tables, runs the # chapter's benchmarks with the pgbench that ships in the image, and proves # the relationships the chapter claims. It never asserts a raw speed: those # belong to your machine. It asserts that A beats B by more than the noise, # that a spike lines up with a checkpoint, and so on. # Every claim prints PROVED; the first one that doesn't hold stops the run. # Takes about five minutes. Close other heavy work first: a noisy neighbor is # part of any benchmark, which is one of the chapter's points. LAB_COMPOSE=28-benchmarking.compose.yml . "$(dirname "$0")/lib.sh" # sql [psql args]: run psql on the server, unaligned, quiet. sql() { local db="$1"; shift "${COMPOSE[@]}" exec -T -e PGOPTIONS="-c client_min_messages=warning" postgres \ psql -X -q -At -v ON_ERROR_STOP=1 -d "$db" "$@" } # sh