Files
EvoFirewall/scripts/bench/runtime.sh
T
Denozordec 57b7652d4d
quality / changes (push) Successful in 6s
quality / commitlint (push) Skipped
quality / openapi (push) Successful in 28s
quality / web (push) Successful in 57s
quality / api (push) Successful in 1m35s
quality / linux-agent-smoke (push) Successful in 24s
quality / docker-check (push) Failing after 3m20s
CD / quality (push) Failing after 6m56s
CD / publish (push) Skipped
fix(ci): support ipset sockets and deployed image smoke checks
2026-10-26 14:14:51 +07:00

58 lines
3.2 KiB
Bash

#!/usr/bin/env sh
# Linux/Docker host, isolated fixture only. Pass the same image to repeat a run.
set -eu
image="${1:?Usage: runtime.sh IMAGE OUTPUT_DIR}"
out="${2:?OUTPUT_DIR required}"
[ ! -e "$out" ] || { echo 'Use a new output directory for each baseline run' >&2; exit 1; }
mkdir -p "$out"
id="evofw-bench-$(date +%s)-$$"
volume="$id-data"
load_id="$id-load"
cleanup() {
docker logs "$id" >"$out/container.log" 2>&1 || true
[ -z "${sampler:-}" ] || { kill "$sampler" 2>/dev/null || true; wait "$sampler" 2>/dev/null || true; }
docker rm -fv "$load_id" >/dev/null 2>&1 || true
docker rm -f "$id" >/dev/null 2>&1 || true
docker volume rm "$volume" >/dev/null 2>&1 || true
}
trap cleanup EXIT HUP INT TERM
docker version >"$out/docker-version.txt"
docker info >"$out/docker-info.txt"
docker image inspect "$image" >"$out/image.json"
if docker volume inspect "$volume" >/dev/null 2>&1; then echo 'Refusing reused benchmark volume' >&2; exit 1; fi
docker volume create "$volume" >/dev/null
started="$(date +%s)"
docker run -d --name "$id" --cpus 2 --memory 4g --network none \
--mount "type=volume,src=$volume,dst=/data" -e EVOFW_ALLOW_UNSAFE=true -e AUTH_REQUIRED=false "$image" >/dev/null
attempts=0
until docker exec "$id" node -e "fetch('http://127.0.0.1:8080/ready').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))" >/dev/null 2>&1; do
attempts=$((attempts + 1)); [ "$attempts" -lt 120 ] || exit 1; sleep 1
done
printf '{"coldReadySeconds":%s,"cpus":2,"memoryBytes":4294967296}\n' "$(( $(date +%s) - started ))" >"$out/startup.json"
docker exec -i "$id" node --input-type=module <scripts/bench/fixture.mjs >"$out/fixture.json"
# Includes CPU, memory, block IO and PIDs. Metrics are raw observations, no claimed gains.
(while docker inspect -f '{{.State.Running}}' "$id" 2>/dev/null | grep -q true; do docker stats --no-stream --format '{{json .}}' "$id"; sleep 1; done) >"$out/stats.jsonl" &
sampler=$!
# The daemon can be remote or reached from a Gitea job container: runner
# localhost is not the API container. A separate nonroot driver joins only the
# API network namespace, so its CPU work is outside the app's 2-CPU quota.
docker create --name "$load_id" --network "container:$id" \
--user 65534:65534 --cap-drop ALL --security-opt no-new-privileges:true \
--pids-limit 128 --cpus 2 --memory 1g --entrypoint node \
-e BENCH_URL=http://127.0.0.1:8080 \
-e "BENCH_P95_LIMIT_MS=${BENCH_P95_LIMIT_MS:-500}" \
-e "BENCH_CONCURRENCY=${BENCH_CONCURRENCY:-10}" \
-e "BENCH_STEADY_CONCURRENCY=${BENCH_STEADY_CONCURRENCY:-2}" \
-e "BENCH_STEADY_INTERVAL_MS=${BENCH_STEADY_INTERVAL_MS:-1200}" \
"$image" /tmp/load.mjs >/dev/null
# docker cp transfers bytes through the Docker API; no runner bind mount or
# container Docker socket is needed. Both modules are readable by the driver UID.
docker cp scripts/bench/load.mjs "$load_id:/tmp/load.mjs"
docker cp scripts/bench/fixture.mjs "$load_id:/tmp/fixture.mjs"
docker start --attach "$load_id" >"$out/load.json" || load_failed=true
[ "$(docker wait "$load_id")" = 0 ] || load_failed=true
cat "$out/load.json"
docker exec "$id" sh -c 'ls -ln /data/app.db*; cat /proc/1/status; cat /proc/1/io' >"$out/db-process.txt"
sh deploy/docker/backup.sh "$id" "$out/backup.db"
[ "${load_failed:-false}" = false ]