#!/bin/sh
|
#
|
# src/test/performance/cfs/pgbench_readwrite.sh
|
#
|
# Phase 13 / A13.1 -- read-write pgbench harness for CFS.
|
#
|
# Same matrix as pgbench_readonly.sh, but each transaction UPDATEs a random
|
# row. This stresses the CFS write path (compress + append to .cfp + journal)
|
# and accumulates dead records; the dead counters are exact at
|
# checkpoints only (run one before reading them), which is the input for the
|
# background compactor (A8.5).
|
#
|
# Usage / environment: identical to pgbench_readonly.sh.
|
|
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
|
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"
|
PGBARGS="-h ${PGHOST:-127.0.0.1} -p ${PGPORT}"
|
|
"$PSQL" $PSQLARGS -v rows="$SCALE" -v payload_len="$PAYLOAD_LEN" \
|
-f "$HERE/cfs_perf_setup.sql"
|
"$PGBENCH" $PGBARGS -i -s 1 >/dev/null 2>&1 || true
|
|
printf '\n=== CFS read-write pgbench (scale=%s rows, payload=%s chars, %ss runs) ===\n\n' \
|
"$SCALE" "$PAYLOAD_LEN" "$DURATION"
|
printf '%-14s %-8s %12s %12s\n' TABLE CLIENTS TPS lat_avg_ms
|
printf '%-14s %-8s %12s %12s\n' ----- ------ --- ----------
|
|
for tbl in $TABLES; do
|
for c in $CLIENTS; do
|
out=$("$PGBENCH" $PGBARGS -n -c "$c" -j "$c" -T "$DURATION" \
|
-f "$HERE/pgbench_readwrite.sql" \
|
-D "scale=$SCALE" -D "table=$tbl" 2>&1)
|
tps=$(printf '%s\n' "$out" | awk '/^tps = / {print $3}')
|
lat_ms=$(printf '%s\n' "$out" | awk '/latency average = / {print $4}')
|
printf '%-14s %-8s %12s %12s\n' "$tbl" "$c" "${tps:-0}" "${lat_ms:-0}"
|
done
|
done
|
|
echo
|
"$PSQL" $PSQLARGS -f "$HERE/cfs_perf_report.sql"
|