Files
mtusi2026lab5/scripts/bench/run-series.sh
T

89 lines
3.5 KiB
Bash
Executable File

#!/bin/sh
# Track 1: every configuration of the given series files, each on a fresh
# stand, under one grid of offered rates. Repeats are interleaved (repeat 1
# of every configuration, then repeat 2), so a slow spell of the host does not
# fall on one configuration.
#
# RATES=400,800,1200 sh scripts/bench/run-series.sh scripts/bench/series/A.conf [...]
#
# Environment: RATES (required), REPEATS (3), STEP (30s), WARMUP (30s),
# STOP_ON_FAIL (1: end a ladder at its first failing step), OUT
# (evidence/track1/raw). Results: <OUT>/<series>/<config>/rep<k>/.
set -eu
cd "$(dirname "$0")/../.."
. scripts/bench/lib.sh
[ $# -gt 0 ] || { echo "usage: RATES=... run-series.sh <series.conf>..." >&2; exit 2; }
: "${RATES:?set RATES, the offered requests per second of the steps, e.g. 400,800,1200}"
repeats=${REPEATS:-3}
step=${STEP:-30s}
warmup=${WARMUP:-30s}
out=${OUT:-evidence/track1/raw}
stop=
[ "${STOP_ON_FAIL:-1}" = 1 ] && stop=-stop-on-fail
# Fixed for every configuration; the API, its pool, maxconn and the database
# CPU come from the series line.
export LB_CPUS=1.0 PG_MEMORY=1G LOADGEN_CPUS=2.0
export MSYS_NO_PATHCONV=1
# One series line: name replicas cpus memory gomemlimit pool maxconn pg_cpus.
run_config() {
series=$1 rep=$2 name=$3 replicas=$4 cpus=$5 memory=$6 gomemlimit=$7 pool=$8 maxconn=$9 pg_cpus=${10}
dir=$out/$series/$name/rep$rep
rm -rf "$dir"
mkdir -p "$dir"
echo "== $series/$name rep $rep: $replicas x $cpus CPU / $memory, pool $pool, maxconn $maxconn, PostgreSQL $pg_cpus CPU"
export API_REPLICAS=$replicas API_CPUS=$cpus API_MEMORY=$memory API_GOMEMLIMIT=$gomemlimit \
DB_MAX_CONNS=$pool API_MAXCONN=$maxconn PG_CPUS=$pg_cpus
docker compose down -v --remove-orphans >/dev/null 2>&1
if ! docker compose up -d --build --wait >"$dir/up.log" 2>&1; then
echo " the stand did not start, see $dir/up.log" >&2
exit 1
fi
meta "$dir/meta.json" "series=$series" "config=$name" "repeat=$rep" \
"api_replicas=$replicas" "api_cpus=$cpus" "api_memory=$memory" "gomemlimit=$gomemlimit" \
"db_max_conns=$pool" "api_maxconn=$maxconn" "pg_cpus=$pg_cpus" "pg_memory=$PG_MEMORY" \
"lb_cpus=$LB_CPUS" "loadgen_cpus=$LOADGEN_CPUS" "rates=$RATES" "step=$step" "warmup=$warmup" \
"stop_on_fail=${STOP_ON_FAIL:-1}" "host_probe_s=$(host_probe)"
sample_docker_stats "$dir/docker-stats.jsonl" &
stats=$!
sample_postgres "$dir/postgres.jsonl" &
pg=$!
# stdin closed: `compose run` would otherwise read it.
BENCH_OUT=$(abspath "$dir") docker compose --profile bench run --rm loadgen bench \
-rates "$RATES" -step "$step" -warmup "$warmup" -scrape $stop >"$dir/loadgen.log" 2>&1 </dev/null ||
echo " loadgen failed, see $dir/loadgen.log"
kill "$stats" "$pg" 2>/dev/null || true
wait "$stats" "$pg" 2>/dev/null || true
docker compose logs --no-color --timestamps lb api 2>&1 | state_log >"$dir/compose.log"
gzip -9 "$dir"/*.jsonl
grep '^step' "$dir/loadgen.log" || true
}
for conf in "$@"; do
[ -r "$conf" ] || { echo "cannot read $conf" >&2; exit 2; }
bad=$(grep -v '^#' "$conf" | awk 'NF && NF != 8')
[ -z "$bad" ] || { echo "$conf: a line needs 8 fields: $bad" >&2; exit 2; }
done
docker compose --profile bench build loadgen >/dev/null
default_ifs=$IFS
newline='
'
for rep in $(seq 1 "$repeats"); do
for conf in "$@"; do
lines=$(grep -v '^#' "$conf" | sed '/^[[:space:]]*$/d')
IFS=$newline
for line in $lines; do
IFS=$default_ifs
# shellcheck disable=SC2086 # the line splits into the fields
run_config "$(basename "$conf" .conf)" "$rep" $line
done
IFS=$default_ifs
done
done
docker compose down -v --remove-orphans >/dev/null 2>&1
echo "results in $out"