120 lines
5.1 KiB
Bash
Executable File
120 lines
5.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# SPDX-License-Identifier: CPAL-1.0
|
|
# Copyright (c) 2026 Marek Novák. Part of Ianitor, under the Common Public Attribution
|
|
# License 1.0: see LICENSE (its Exhibit A is this file's notice).
|
|
#
|
|
# ROADMAP §5 layer 5: load and soak against Caddy, reproducible. Ianitor and two Caddys (as Go
|
|
# starts it, and GOMAXPROCS=2 to match edge's two Pingora worker threads) serve the same route
|
|
# (tests/diff/src/bin/pair.rs) to the same upstream; oha drives each in turn. Results are
|
|
# committed as data: bench/results/<date>-<label>.csv and the raw oha JSON beside it.
|
|
#
|
|
# scripts/bench.sh [label] # needs caddy, oha, jq on PATH
|
|
# nix shell nixpkgs#caddy nixpkgs#oha nixpkgs#jq -c scripts/bench.sh wsl2-ryzen
|
|
#
|
|
# Environment: DURATION (each load run, default 20s), SOAK (the soak run, default 300s; 0 skips
|
|
# it), CONNS (default "1 16 64 256"), BUILD (release or debug, default release).
|
|
# Everything listens on 127.0.0.1; the load generator shares the machine, so absolute numbers
|
|
# say more about the machine than the proxies: compare the rows, not the numbers across machines.
|
|
set -euo pipefail
|
|
|
|
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
|
label=${1:-$(hostname -s 2>/dev/null || echo local)}
|
|
duration=${DURATION:-20s}
|
|
soak=${SOAK:-300}
|
|
conns=${CONNS:-"1 16 64 256"}
|
|
profile=${BUILD:-release}
|
|
for tool in caddy oha jq; do
|
|
command -v "$tool" >/dev/null || { echo "missing: $tool" >&2; exit 2; }
|
|
done
|
|
|
|
flag=--release
|
|
[ "$profile" = debug ] && flag=
|
|
cargo build $flag -q -p ianitor-diff --bin ianitor-pair
|
|
bin="${CARGO_TARGET_DIR:-$root/target}/$profile/ianitor-pair"
|
|
|
|
stamp=$(date -u +%Y-%m-%d)
|
|
dir="$root/bench/results"
|
|
raw="$dir/$stamp-$label"
|
|
mkdir -p "$raw"
|
|
csv="$dir/$stamp-$label.csv"
|
|
|
|
info=$(mktemp)
|
|
"$bin" --caddy "$(command -v caddy)" >"$info" &
|
|
pair=$!
|
|
trap 'kill $pair 2>/dev/null; wait $pair 2>/dev/null; rm -f "$info"' EXIT
|
|
for _ in $(seq 1 100); do
|
|
[ -s "$info" ] && break
|
|
sleep 0.2
|
|
done
|
|
[ -s "$info" ] || { echo "ianitor-pair did not start" >&2; exit 1; }
|
|
|
|
# The machine, for the record.
|
|
{
|
|
echo "label: $label"
|
|
echo "date: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
echo "kernel: $(uname -sr)"
|
|
grep -m1 'model name' /proc/cpuinfo 2>/dev/null | sed 's/^.*: /cpu: /' || true
|
|
echo "cpus: $(nproc)"
|
|
grep -m1 MemTotal /proc/meminfo 2>/dev/null | sed 's/^MemTotal: */memory: /' || true
|
|
grep -qi microsoft /proc/version 2>/dev/null && echo "virtualisation: WSL2" || true
|
|
echo "build: $(jq -r .build "$info"); edge worker threads: $(jq -r .edge_threads "$info")"
|
|
echo "caddy: $(jq -r .caddy_version "$info")"
|
|
echo "oha: $(oha --version 2>/dev/null | head -1)"
|
|
echo "duration: $duration per run; soak: ${soak}s"
|
|
} >"$raw/machine.txt"
|
|
|
|
# The process to sample for memory: edge runs inside ianitor-pair; each Caddy is a child of it.
|
|
pid_of() {
|
|
local port=$1
|
|
ss -Hltnp "sport = :$port" 2>/dev/null | grep -Eo 'pid=[0-9]+' | head -1 | cut -d= -f2
|
|
}
|
|
rss_kb() { awk '/VmRSS/ {print $2}' "/proc/$1/status" 2>/dev/null || echo 0; }
|
|
|
|
echo "engine,scenario,connections,duration_s,requests,rps,p50_ms,p90_ms,p99_ms,max_ms,success_rate,non_2xx,rss_kb_after" >"$csv"
|
|
run() { # engine scenario conns duration url [oha args...]
|
|
local engine=$1 scenario=$2 c=$3 d=$4 url=$5
|
|
shift 5
|
|
local file="$raw/$engine-$scenario-c$c.json"
|
|
if ! oha --no-tui --insecure --output-format json -c "$c" -z "$d" "$@" "$url" >"$file" 2>"$file.err"; then
|
|
echo "oha failed for $engine $scenario c$c:" >&2
|
|
cat "$file.err" >&2
|
|
fi
|
|
[ -s "$file.err" ] || rm -f "$file.err"
|
|
local pid
|
|
pid=$(pid_of "$(echo "$url" | sed -E 's#.*:([0-9]+)/.*#\1#')")
|
|
jq -r --arg e "$engine" --arg s "$scenario" --arg c "$c" --arg rss "$(rss_kb "${pid:-0}")" '
|
|
def ms: if . == null then "" else (. * 1000 * 100 | round / 100 | tostring) end;
|
|
[$e, $s, $c,
|
|
(.summary.total | . * 100 | round / 100 | tostring),
|
|
((.statusCodeDistribution // {}) | to_entries | map(.value) | add // 0 | tostring),
|
|
(.summary.requestsPerSec | round | tostring),
|
|
(.latencyPercentiles.p50 | ms), (.latencyPercentiles.p90 | ms), (.latencyPercentiles.p99 | ms),
|
|
(.summary.slowest | ms),
|
|
(.summary.successRate | tostring),
|
|
((.statusCodeDistribution // {}) | to_entries | map(select(.key | startswith("2") | not) | .value) | add // 0 | tostring),
|
|
$rss] | join(",")' "$file" >>"$csv"
|
|
tail -1 "$csv"
|
|
}
|
|
|
|
for engine in ianitor caddy caddy_gomaxprocs2; do
|
|
https=$(jq -r ".$engine.https" "$info")
|
|
http=$(jq -r ".$engine.http" "$info")
|
|
url="https://localhost:${https##*:}/"
|
|
for c in $conns; do
|
|
run "$engine" https-h1-keepalive "$c" "$duration" "$url"
|
|
run "$engine" https-h2 "$c" "$duration" "$url" --http2
|
|
done
|
|
# A new TLS connection per request: the handshake dominates.
|
|
run "$engine" https-h1-new-conn 16 "$duration" "$url" --disable-keepalive
|
|
# The plain-HTTP listener's redirect (no upstream).
|
|
run "$engine" http-redirect 64 "$duration" "http://localhost:${http##*:}/" --redirect 0
|
|
done
|
|
|
|
if [ "$soak" -gt 0 ]; then
|
|
for engine in ianitor caddy; do
|
|
https=$(jq -r ".$engine.https" "$info")
|
|
run "$engine" soak-https-h1 32 "${soak}s" "https://localhost:${https##*:}/"
|
|
done
|
|
fi
|
|
echo "results: $csv"
|