New infra:
- examples/http-server-noarena.lsp: same HTTP server minus the
heap-snapshot/heap-restore arena loop. Isolates whether the GC
build actually holds memory under real traffic, independent
of the portable snapshot pattern.
- tests/bench-gc-http.sh: drives 5,000 concurrent requests per
cell across the full 2x2 matrix {no-GC, GC} x {snapshot, no}.
- Makefile: new `bench-gc-http` target.
Extended benches to exercise both asm binaries:
- tests/bench-hashset.sh now runs against both asm/uncommonlisp
and asm/uncommonlisp-gc, with set +e so a GC-build crash on
one workload doesn't abort the other.
- tests/web-benchmark.sh adds a dedicated asm-gc row (and prints
its stripped binary size) so the HTTP throughput comparison
reports both.
Whitepaper updates:
- §6.6.4 "Validation: HTTP Server Under Sustained Load" — the
4-cell memory matrix. 3/4 cells green; cell 4 (GC + no
snapshot) crashes at first GC trigger — another instance of
the conservative-scan type-confusion class we already fixed
once at the env/string boundary. Logged as a known issue
rather than shipping a partial fix under time pressure.
heap-snapshot + heap-restore remains the recommended pattern
for production asm code; the naive GC is diagnostic + control
group, not a replacement for the arena discipline.
- §6.5 hash-set speedup table slightly softened to ~15-20x (was
15-21x) since run-to-run noise on a shared laptop shifts the
per-phase ratio by a few percent. Ratio is stable to first
order.
- §8.6 narrative references the ~1280x symbolic-vs-brute-force
figure instead of the stale 40x.
- §6 reproducibility list now lists `make bench-gc-http`.
All 137 asm no-GC + 137 asm GC + 189 shared functional tests
still pass.
156 lines
5.6 KiB
Bash
Executable file
156 lines
5.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# web-benchmark.sh — race the three uncommonlisp HTTP servers
|
|
# against Python http.server and busybox httpd.
|
|
#
|
|
# No wrk/ab/nginx dependency — we use xargs+curl for concurrency.
|
|
#
|
|
# Fixed 1KB body at /bench for all servers. Wall-clock time over
|
|
# N parallel-safe requests = throughput.
|
|
|
|
set -u
|
|
cd "$(dirname "$0")/.."
|
|
|
|
REQUESTS=${REQUESTS:-500}
|
|
CONCURRENCY=${CONCURRENCY:-10}
|
|
PY="python3 uncommonlisp.py --fast"
|
|
C="./c/uncommonlisp"
|
|
ASM="./asm/uncommonlisp"
|
|
ASM_GC="./asm/uncommonlisp-gc"
|
|
|
|
# Track every server PID we spawn; the EXIT trap kills them all.
|
|
# Asm has no GC — a leaked server leaks 64 MB per heap growth
|
|
# indefinitely. Belt + suspenders: kill the whole process group too.
|
|
declare -a SPAWNED_PIDS=()
|
|
|
|
cleanup() {
|
|
local pid
|
|
for pid in "${SPAWNED_PIDS[@]}"; do
|
|
kill "$pid" 2>/dev/null
|
|
done
|
|
sleep 0.2
|
|
for pid in "${SPAWNED_PIDS[@]}"; do
|
|
kill -9 "$pid" 2>/dev/null
|
|
done
|
|
rm -rf "${STATIC_DIR:-/nonexistent/xyz}"
|
|
# Final sanity: any stray servers from examples/http-server?
|
|
# Narrow to processes actually serving the HTTP example, not the
|
|
# shell running this script or tmux sessions with "uncommonlisp"
|
|
# in their name.
|
|
local strays
|
|
strays=$(pgrep -u "$USER" -f 'examples/http-server\.lsp|http\.server 8080' | wc -l)
|
|
if [ "$strays" -gt 0 ]; then
|
|
echo "WARNING: $strays HTTP server process(es) still running:" >&2
|
|
pgrep -u "$USER" -af 'examples/http-server\.lsp|http\.server 8080' >&2
|
|
pkill -9 -u "$USER" -f 'examples/http-server\.lsp|http\.server 8080' 2>/dev/null
|
|
fi
|
|
}
|
|
trap cleanup EXIT INT TERM
|
|
|
|
pad() { printf " %-36s " "$1"; }
|
|
|
|
bench_one() {
|
|
local label="$1" port="$2" path="$3"
|
|
pad "$label"
|
|
# Warm up
|
|
curl -s "http://localhost:$port$path" > /dev/null
|
|
# Measure
|
|
local t0 t1
|
|
t0=$(date +%s.%N)
|
|
seq 1 "$REQUESTS" | xargs -P "$CONCURRENCY" -I_ \
|
|
curl -s -o /dev/null "http://localhost:$port$path"
|
|
t1=$(date +%s.%N)
|
|
python3 -c "
|
|
t = float('$t1') - float('$t0')
|
|
rps = $REQUESTS / t
|
|
print(f'{rps:8.0f} req/s ({t:.3f}s total, concurrency $CONCURRENCY)')"
|
|
}
|
|
|
|
# Setup a 1KB static file for file-serving benchmarks
|
|
STATIC_DIR=$(mktemp -d)
|
|
printf '%.0s0123456789abcdef0123456789abcdef' {1..32} > "$STATIC_DIR/bench"
|
|
|
|
echo "═══════════════════════════════════════════════════════════════"
|
|
echo "HTTP benchmark — $REQUESTS requests, concurrency $CONCURRENCY"
|
|
echo "═══════════════════════════════════════════════════════════════"
|
|
echo
|
|
|
|
# Helper to start + wait for port ready. Adds pid to SPAWNED_PIDS so
|
|
# the EXIT trap kills it even if the script dies unexpectedly.
|
|
start_server() {
|
|
local cmd="$1" port="$2"
|
|
eval "$cmd" > /dev/null 2>&1 &
|
|
local pid=$!
|
|
SPAWNED_PIDS+=("$pid")
|
|
for _ in $(seq 1 20); do
|
|
if curl -s -o /dev/null -w "%{http_code}" "http://localhost:$port/" 2>/dev/null | grep -q 200; then
|
|
echo "$pid"
|
|
return 0
|
|
fi
|
|
sleep 0.1
|
|
done
|
|
kill "$pid" 2>/dev/null
|
|
return 1
|
|
}
|
|
|
|
stop_server() {
|
|
local pid="$1"
|
|
# SIGTERM first; if the process is blocked in accept() it may not
|
|
# exit cleanly, so force-kill after a short grace period.
|
|
kill "$pid" 2>/dev/null
|
|
for _ in 1 2 3 4 5; do
|
|
kill -0 "$pid" 2>/dev/null || break
|
|
sleep 0.1
|
|
done
|
|
kill -9 "$pid" 2>/dev/null
|
|
wait "$pid" 2>/dev/null
|
|
sleep 0.2
|
|
}
|
|
|
|
# ── uncommonlisp Python ──
|
|
PID=$(start_server "$PY examples/http-server.lsp" 8080)
|
|
bench_one "uncommonlisp Python (/bench, 1 KB)" 8080 /bench
|
|
stop_server "$PID"
|
|
|
|
# ── uncommonlisp C ──
|
|
PID=$(start_server "$C examples/http-server.lsp" 8080)
|
|
bench_one "uncommonlisp C (/bench, 1 KB)" 8080 /bench
|
|
stop_server "$PID"
|
|
|
|
# ── uncommonlisp asm (bump-only) ──
|
|
PID=$(start_server "$ASM < examples/http-server.lsp" 8080)
|
|
bench_one "uncommonlisp asm (/bench, 1 KB)" 8080 /bench
|
|
stop_server "$PID"
|
|
|
|
# ── uncommonlisp asm-gc (naive mark-sweep + meta-GC build) ──
|
|
if [ -x "$ASM_GC" ]; then
|
|
PID=$(start_server "$ASM_GC < examples/http-server.lsp" 8080)
|
|
bench_one "uncommonlisp asm-gc (/bench, 1 KB)" 8080 /bench
|
|
stop_server "$PID"
|
|
fi
|
|
|
|
# ── Python http.server (stdlib) ──
|
|
(cd "$STATIC_DIR" && python3 -m http.server 8080 > /dev/null 2>&1) &
|
|
PID=$!
|
|
SPAWNED_PIDS+=("$PID")
|
|
sleep 1
|
|
bench_one "python3 -m http.server (1 KB file)" 8080 /bench
|
|
stop_server "$PID"
|
|
|
|
# ── busybox httpd ──
|
|
busybox httpd -f -p 127.0.0.1:8080 -h "$STATIC_DIR" > /dev/null 2>&1 &
|
|
PID=$!
|
|
SPAWNED_PIDS+=("$PID")
|
|
sleep 0.5
|
|
bench_one "busybox httpd (1 KB file)" 8080 /bench
|
|
stop_server "$PID"
|
|
|
|
echo
|
|
echo "═══════════════════════════════════════════════════════════════"
|
|
echo "Binary sizes"
|
|
echo "═══════════════════════════════════════════════════════════════"
|
|
printf " uncommonlisp asm: %s\n" "$(du -b asm/uncommonlisp | cut -f1) bytes"
|
|
[ -x asm/uncommonlisp-gc ] && \
|
|
printf " uncommonlisp asm-gc: %s\n" "$(du -b asm/uncommonlisp-gc | cut -f1) bytes (GC_NAIVE build)"
|
|
printf " uncommonlisp C: %s\n" "$(du -b c/uncommonlisp | cut -f1) bytes"
|
|
printf " busybox httpd: %s\n" "$(du -b /usr/bin/busybox | cut -f1) bytes (multi-call)"
|
|
printf " python3: %s bytes (interpreter binary)\n" "$(du -bL $(which python3) | cut -f1)"
|