Add a NATS cluster message-speed bench (throughput and delay).
Some checks are pending
offline / test (push) Waiting to run

Client LXC 510 against nats-a/b/c at several core and JetStream r=3 loads.
This commit is contained in:
George Lambert 2026-09-12 00:56:48 -04:00
parent 8f0ea8dd31
commit fef7590c27
34 changed files with 708 additions and 1 deletions

View file

@ -0,0 +1,106 @@
#!/usr/bin/env bash
# Message throughput and delay ladder against the 3-node vmbr1 cluster.
# Prefers a client that is not a nats-* server (px-worker LXC 510).
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
# shellcheck disable=SC1091
. "$ROOT/client.env"
export PATH="/usr/sbin:/usr/bin:/bin:/usr/local/bin:$PATH"
STAMP="$(date -u +%Y%m%dT%H%M%SZ)"
OUT="${BENCH_OUT:-$ROOT/results/$STAMP}"
CLIENT_VMID="${CLIENT_VMID:-510}"
mkdir -p "$OUT"
ensure_nats_cli() {
local vmid="$1"
sudo pct exec "$vmid" -- bash -lc '
set -e
export DEBIAN_FRONTEND=noninteractive
export PATH=/usr/local/bin:/usr/bin:/bin
if [[ ! -x /usr/local/bin/nats ]]; then
apt-get install -y --no-install-recommends unzip curl ca-certificates >/dev/null
curl -fsSL https://github.com/nats-io/natscli/releases/download/v0.1.6/nats-0.1.6-linux-amd64.zip -o /tmp/natscli.zip
rm -rf /tmp/natscli && mkdir -p /tmp/natscli
unzip -o /tmp/natscli.zip -d /tmp/natscli >/dev/null
BIN=$(find /tmp/natscli -type f -name nats | head -1)
install -m 0755 "$BIN" /usr/local/bin/nats
fi
nats --version
'
}
run_one() {
local name="$1"
shift
echo "=== $name ===" | tee "$OUT/$name.txt"
# nats bench writes csv itself when --csv is a path inside the guest
sudo pct exec "$CLIENT_VMID" -- bash -lc "
export PATH=/usr/local/bin:/usr/bin:/bin
export NATS_URL='$NATS_URL'
nats bench --no-progress --csv=/tmp/bench.csv $*
" | tee -a "$OUT/$name.txt"
sudo pct exec "$CLIENT_VMID" -- cat /tmp/bench.csv >"$OUT/$name.csv" || true
}
echo "client LXC $CLIENT_VMID NATS_URL=$NATS_URL out=$OUT"
ensure_nats_cli "$CLIENT_VMID"
# Core NATS pub/sub — increasing publishers (same 128 B payload)
run_one core-1p1s-50k-128 bench.core.a --pub 1 --sub 1 --msgs 50000 --size 128
run_one core-4p4s-100k-128 bench.core.b --pub 4 --sub 4 --msgs 100000 --size 128
run_one core-8p8s-200k-128 bench.core.c --pub 8 --sub 8 --msgs 200000 --size 128
run_one core-4p4s-50k-1k bench.core.d --pub 4 --sub 4 --msgs 50000 --size 1024
js_rm() {
sudo pct exec "$CLIENT_VMID" -- bash -lc "
export PATH=/usr/local/bin:/usr/bin:/bin
export NATS_URL='$NATS_URL'
nats stream rm benchstream --force >/dev/null 2>&1 || true
"
}
# JetStream file store, replicas=3 (matches product streams)
js_rm
run_one js-1p-20k-128-r3 bench.js.a --js --purge --pub 1 --msgs 20000 --size 128 --replicas 3 --storage file --maxbytes=512MB --stream=benchstream
js_rm
run_one js-4p-50k-128-r3 bench.js.b --js --purge --pub 4 --msgs 50000 --size 128 --replicas 3 --storage file --maxbytes=512MB --stream=benchstream
js_rm
run_one js-4p-20k-1k-r3 bench.js.c --js --purge --pub 4 --msgs 20000 --size 1024 --replicas 3 --storage file --maxbytes=512MB --stream=benchstream
js_rm
run_one js-2p2s-20k-128-r3 bench.js.d --js --purge --pub 2 --sub 2 --msgs 20000 --size 128 --replicas 3 --storage file --maxbytes=512MB --pull --stream=benchstream
js_rm
# Round-trip delay (two connections, through the cluster) at several loads
sudo pct exec "$CLIENT_VMID" -- bash -lc "
set -e
export PATH=/usr/local/bin:/usr/bin:/bin
export NATS_URL='$NATS_URL'
mkdir -p /tmp/nats-lat
cd /tmp/nats-lat
if [[ ! -d node_modules/nats ]]; then
npm init -y >/dev/null
npm install --no-audit --no-fund nats@2 >/dev/null
fi
" >/dev/null
sudo pct push "$CLIENT_VMID" "$ROOT/scripts/latency.mjs" /tmp/nats-lat/latency.mjs || \
sudo pct exec "$CLIENT_VMID" -- bash -c 'cat > /tmp/nats-lat/latency.mjs' < "$ROOT/scripts/latency.mjs"
lat() {
local name="$1" n="$2" sz="$3" p="$4" mode="${5:-flood}"
echo "=== $name ===" | tee "$OUT/$name.txt"
sudo pct exec "$CLIENT_VMID" -- bash -lc "
export PATH=/usr/local/bin:/usr/bin:/bin
export NATS_URL='$NATS_URL'
cd /tmp/nats-lat
node latency.mjs $n $sz $p $mode
" | tee -a "$OUT/$name.txt"
}
# copy latest probe
sudo pct exec "$CLIENT_VMID" -- bash -c 'cat > /tmp/nats-lat/latency.mjs' < "$ROOT/scripts/latency.mjs"
lat lat-ping-1k-128 1000 128 1 ping
lat lat-1p-5k-128 5000 128 1 flood
lat lat-4p-10k-128 10000 128 4 flood
lat lat-8p-20k-128 20000 128 8 flood
lat lat-4p-5k-1k 5000 1024 4 flood
python3 "$ROOT/scripts/bench-report.py" "$OUT" >"$OUT/BENCH.md"
cp "$OUT/BENCH.md" "$ROOT/BENCH.md"
echo "wrote $OUT/BENCH.md and $ROOT/BENCH.md"