Files
mtusi2026lab3/scripts/run_optimization.sh
T
2026-10-22 17:21:52 +03:00

66 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
mkdir -p evidence/scale/optimization
run_case() {
local name="$1"
local replicas="$2"
local cpus="$3"
local memory="$4"
export API_REPLICAS="$replicas"
export API_CPUS="$cpus"
export API_MEMORY="$memory"
echo "=== $name: $replicas replicas, $cpus CPU and $memory per replica ==="
docker compose -f compose.yaml -f compose.scale.yaml down
services=(postgres redis migrate nginx)
for ((i=1; i<=replicas; i++)); do
services+=("api-$i")
done
docker compose -f compose.yaml -f compose.scale.yaml up -d --build "${services[@]}"
ready=0
for ((attempt=1; attempt<=60; attempt++)); do
if curl --fail --silent http://localhost:8080/health/ready >/dev/null; then
ready=1
break
fi
sleep 2
done
if ((ready == 0)); then
echo "ERROR: API readiness timeout" >&2
exit 1
fi
python3 tests/load.py \
--duration 15 \
--concurrency 16 \
--output "evidence/scale/optimization/${name}-warmup.json"
for run in 1 2 3; do
python3 tests/load.py \
--duration 60 \
--concurrency 16 \
--output "evidence/scale/optimization/${name}-run${run}.json"
done
}
run_case before 4 0.5 256m
run_case after 2 1.0 512m
API_REPLICAS=2 API_CPUS=1.0 API_MEMORY=512m \
docker compose -f compose.yaml -f compose.scale.yaml down
API_REPLICAS=2 API_CPUS=1.0 API_MEMORY=512m \
docker compose -f compose.yaml -f compose.scale.yaml up -d --build \
postgres redis migrate api-1 api-2 nginx
echo "=== Optimization experiment completed ==="