#!/bin/sh # # src/test/performance/cfs/pgbench_readonly.sh # # Phase 13 / A13.1 -- read-only pgbench harness for CFS. # # Measures point-lookup throughput and latency on four tables that share the # same data but differ in storage policy: plain (baseline), lz4/1, zstd/1, # zstd/3. For each table the script runs pgbench across a matrix of client # counts and prints a TPS / p95-latency / compression-ratio report. # # Usage: # PG_BINDIR=/path/to/pg/bin ./pgbench_readonly.sh [PGDATA] # # Environment: # PG_BINDIR directory containing initdb/pg_ctl/pgbench/psql (required) # PGPORT port for the temp cluster (default 55413) # SCALE number of rows loaded (default 10000) # PAYLOAD_LEN payload length in chars (default 320) # CLIENTS space-separated client counts (default "1 8 32 64") # DURATION per-run duration in seconds (default 15) # # If a PGDATA argument is given the harness starts/stops a throwaway cluster # there; otherwise it connects to an already-running server via $PGHOST/$PGPORT. set -eu HERE=$(cd "$(dirname "$0")" && pwd) : "${PG_BINDIR:?PG_BINDIR must point at the postgres bin directory}" : "${SCALE:=10000}" : "${PAYLOAD_LEN:=320}" : "${CLIENTS:=1 8 32 64}" : "${DURATION:=15}" : "${PGPORT:=55413}" : "${LICENSE_FILE:=/tmp/license.xml}" PSQL="$PG_BINDIR/psql" PGBENCH="$PG_BINDIR/pgbench" TABLES="perf_plain perf_lz4_1 perf_zstd_1 perf_zstd_3" STARTED_CLUSTER=0 PGDATA="${1:-}" cleanup() { if [ "$STARTED_CLUSTER" = 1 ]; then "$PG_BINDIR/pg_ctl" -D "$PGDATA" -m fast stop >/dev/null 2>&1 || true fi } trap cleanup EXIT INT TERM if [ -n "$PGDATA" ]; then # Bring up a throwaway cluster. export PGHOST=127.0.0.1 if [ ! -d "$PGDATA" ]; then "$PG_BINDIR/initdb" -D "$PGDATA" --license "$LICENSE_FILE" --auth trust --no-locale -E UTF8 >/dev/null fi "$PG_BINDIR/pg_ctl" -D "$PGDATA" -l "$PGDATA/perf.log" \ -o "-p $PGPORT -c shared_buffers=256MB -c max_connections=200" start >/dev/null 2>&1 STARTED_CLUSTER=1 fi export PGDATABASE=postgres PSQLARGS="-h ${PGHOST:-127.0.0.1} -p ${PGPORT} -v ON_ERROR_STOP=1" # pgbench does not understand psql-only flags like -v. PGBARGS="-h ${PGHOST:-127.0.0.1} -p ${PGPORT}" # Schema + data, identical across all four tables. "$PSQL" $PSQLARGS -v rows="$SCALE" -v payload_len="$PAYLOAD_LEN" \ -f "$HERE/cfs_perf_setup.sql" # Warm pgbench. "$PGBENCH" $PGBARGS -i -s 1 >/dev/null 2>&1 || true printf '\n=== CFS read-only pgbench (scale=%s rows, payload=%s chars, %ss runs) ===\n\n' \ "$SCALE" "$PAYLOAD_LEN" "$DURATION" printf '%-14s %-8s %12s %12s %12s\n' TABLE CLIENTS TPS lat_avg_us cpu_pct printf '%-14s %-8s %12s %12s %12s\n' ----- ------ --- --------- ------ for tbl in $TABLES; do for c in $CLIENTS; do # Latency average (us) and per-run TPS. out=$("$PGBENCH" $PGBARGS -n -c "$c" -j "$c" -T "$DURATION" \ -f "$HERE/pgbench_readonly.sql" \ -D "scale=$SCALE" -D "table=$tbl" 2>&1) # "tps = 5632.49 (without initial connection time)" tps=$(printf '%s\n' "$out" | awk '/^tps = / {print $3}') # "latency average = 0.178 ms" -> microseconds = value * 1000 lat_ms=$(printf '%s\n' "$out" | awk '/latency average = / {print $4}') lat_us=$(awk -v v="$lat_ms" 'BEGIN { if (v=="") print 0; else printf "%.0f", v*1000 }') # CPU% is a coarse, optional signal read from /proc/stat for the run; # leave as '-' when not measurable in a portable way. printf '%-14s %-8s %12s %12s %12s\n' "$tbl" "$c" "${tps:-0}" "${lat_us:-0}" "-" done done echo "$PSQL" $PSQLARGS -f "$HERE/cfs_perf_report.sql"