ЛР 3 — БПИ2303 — Морару — на 5: API на TypeScript/Node, HAProxy, failover, трек 1

This commit is contained in:
celis
2026-10-29 20:59:24 +03:00
parent 0ab3a341aa
commit c4f9eb7648
83 changed files with 1862 additions and 19 deletions
+21
View File
@@ -0,0 +1,21 @@
#!/bin/sh
# Level 4: under constant k6 load, stop each API replica in turn (restoring the previous one first).
# Prints per-replica k6 summary: successful RPS, errors, latency. Recovery = downtime of the failed replica.
set -eu
cd "$(dirname "$0")/.."
RATE=${RATE:-300}
for cid in $(docker compose ps -q api); do
name=$(docker inspect -f '{{.Name}}' "$cid")
docker run --rm --network messenger-lab3_frontend -v "$PWD/research/k6:/k6:ro" \
-e RATE="$RATE" -e DURATION=20s -e PAIRS=5 grafana/k6:1.8.2 run -q /k6/messenger.js 2>/dev/null | tail -1 > /tmp/failover-each.$$ &
sleep 12 # setup + 5 s of steady load
t0=$(date +%s)
docker stop "$cid" >/dev/null # graceful: readiness 503 -> LB DOWN -> drain
t1=$(date +%s)
wait
echo "stopped $name in $((t1 - t0)) s: $(cat /tmp/failover-each.$$)"
docker start "$cid" >/dev/null
until [ "$(docker inspect -f '{{.State.Health.Status}}' "$cid")" = healthy ]; do sleep 1; done
echo "restored $name"
done
rm -f /tmp/failover-each.$$