Files
2026-10-23 18:10:07 +03:00

91 lines
2.6 KiB
Bash

#!/bin/sh
set -eu
DURATION="${DURATION:-60}"
WARMUP="${WARMUP:-15}"
RPS_LIST="${RPS_LIST:-100 200 300 400 500 800}"
OUTDIR="evidence/track1"
mkdir -p "$OUTDIR"
PROFILES="
A1:1:1.0:256M
A2:2:0.5:128M
A4:4:0.25:64M
B1:1:0.5:128M
B2:2:0.5:128M
B4:4:0.5:128M
"
for prof in $PROFILES; do
name=$(echo "$prof" | cut -d: -f1)
n=$(echo "$prof" | cut -d: -f2)
cpu=$(echo "$prof" | cut -d: -f3)
mem=$(echo "$prof" | cut -d: -f4)
echo "=== profile $name: replicas=$n cpu=$cpu mem=$mem"
export API_REPLICAS="$n"
export API_CPU_PER_REPLICA="$cpu"
export API_MEM_PER_REPLICA="$mem"
docker compose --env-file .env down --remove-orphans --timeout 30 </dev/null || true
docker compose --env-file .env up -d --build </dev/null
i=0
while [ "$i" -lt 90 ]; do
if curl -sf http://localhost:8080/health/ready >/dev/null 2>&1; then
echo " ready after ${i}s"
break
fi
i=$((i + 1))
sleep 1
done
replicas_up=$(docker compose --env-file .env ps -q api </dev/null | wc -l)
echo " api containers up: $replicas_up (expected $n)"
if [ "$replicas_up" -ne "$n" ]; then
echo "ERROR: expected $n api replicas, got $replicas_up" >&2
exit 1
fi
for rps in $RPS_LIST; do
echo "--- $name target_rps=$rps"
docker compose --env-file .env exec -T postgres psql -U messenger -d messenger \
-v ON_ERROR_STOP=1 < fixtures/seed.sql >/dev/null
docker compose --env-file .env exec -T postgres psql -U messenger -d messenger \
-c "ANALYZE messages; ANALYZE idempotency_keys;" >/dev/null
sleep 3
: > "$OUTDIR/${name}-rps${rps}-stats.txt"
(
while true; do
docker stats --no-stream --format \
'{{.Name}} {{.CPUPerc}} {{.MemUsage}}' >> "$OUTDIR/${name}-rps${rps}-stats.txt"
sleep 2
done
) &
STATS_PID=$!
sleep 1
python3 tests/openloop.py \
--target-rps "$rps" --duration "$DURATION" --warmup "$WARMUP" \
--output "$OUTDIR/${name}-rps${rps}.json"
kill "$STATS_PID" 2>/dev/null || true
wait "$STATS_PID" 2>/dev/null || true
docker compose --env-file .env exec -T postgres psql -U messenger -d messenger \
-At -F'|' -c "
SELECT 'state', state, count(*) FROM pg_stat_activity WHERE datname='messenger' GROUP BY state
UNION ALL
SELECT 'wait', wait_event_type, count(*) FROM pg_stat_activity WHERE datname='messenger' GROUP BY wait_event_type
UNION ALL
SELECT 'maxconns', 'setting', setting::int FROM pg_settings WHERE name='max_connections'
" > "$OUTDIR/${name}-rps${rps}-pg.txt" || true
done
done
echo "=== done, results in $OUTDIR ==="
ls -la "$OUTDIR" | tail -5