Added tcp-listen/accept/connect/recv/send/close to Python, C, and asm. One examples/http-server.lsp runs identically in all three impls and serves HTTP/1.0 with routing, content-type, and content-length headers. asm additions: - SYS_SOCKET/BIND/LISTEN/ACCEPT/CONNECT/SETSOCKOPT syscalls - 6 tcp-* builtins using the existing port encoding (SPECIAL ≥ 1000) - bi_tcp_connect: dotted-quad IPv4 parser, no DNS dependency Defects fixed along the way (surfaced by the HTTP server): - string-append: was 2-arg only; now variadic (walks arg list twice) - number->string: was stubbed to VAL_VOID; now correctly writes digits into a heap-allocated string (incl. negative handling) - String-literal reader: \r and \0 escape sequences now handled (was silently dropping backslash, treating them as literal 'r' / '0') - tcp_accept: sockaddr buffer was 8 bytes, now 16 (was corrupting caller's stack when accept wrote full struct sockaddr_in) Pinocchio benchmark (tests/web-benchmark.sh): At concurrency=20, 1000 requests, serving a 1KB body: uncommonlisp Python 373 req/s uncommonlisp C 370 req/s uncommonlisp asm 370 req/s python3 http.server 381 req/s (stdlib reference) busybox httpd 382 req/s (production reference) All five converge within 3% — the client (curl fork/exec) is the bottleneck, not the server. Our single-threaded blocking servers are indistinguishable from battle-tested ones at this load. Binary sizes: uncommonlisp asm 45 KB (HTTP + everything else) busybox httpd 2.1 MB (multi-call binary) python3 8 MB (interpreter) The asm HTTP server is 46× smaller than busybox and 176× smaller than Python, serves from 7 Linux syscalls, and the entire protocol handler is 70 lines of portable Scheme. Test counts: 132 asm (up 1), rest unchanged. All green.
104 lines
3.8 KiB
Bash
Executable file
104 lines
3.8 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"
|
|
|
|
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"
|
|
trap "rm -rf $STATIC_DIR" EXIT
|
|
|
|
echo "═══════════════════════════════════════════════════════════════"
|
|
echo "HTTP benchmark — $REQUESTS requests, concurrency $CONCURRENCY"
|
|
echo "═══════════════════════════════════════════════════════════════"
|
|
echo
|
|
|
|
# Helper to start + wait for port ready
|
|
start_server() {
|
|
local cmd="$1" port="$2"
|
|
eval "$cmd" > /dev/null 2>&1 &
|
|
local 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
|
|
}
|
|
|
|
# ── uncommonlisp Python ──
|
|
PID=$(start_server "$PY examples/http-server.lsp" 8080)
|
|
bench_one "uncommonlisp Python (/bench, 1 KB)" 8080 /bench
|
|
kill "$PID" 2>/dev/null; wait "$PID" 2>/dev/null
|
|
sleep 0.3
|
|
|
|
# ── uncommonlisp C ──
|
|
PID=$(start_server "$C examples/http-server.lsp" 8080)
|
|
bench_one "uncommonlisp C (/bench, 1 KB)" 8080 /bench
|
|
kill "$PID" 2>/dev/null; wait "$PID" 2>/dev/null
|
|
sleep 0.3
|
|
|
|
# ── uncommonlisp asm ──
|
|
PID=$(start_server "$ASM < examples/http-server.lsp" 8080)
|
|
bench_one "uncommonlisp asm (/bench, 1 KB)" 8080 /bench
|
|
kill "$PID" 2>/dev/null; wait "$PID" 2>/dev/null
|
|
sleep 0.3
|
|
|
|
# ── Python http.server (stdlib) ──
|
|
(cd "$STATIC_DIR" && python3 -m http.server 8080 > /dev/null 2>&1) &
|
|
PID=$!
|
|
sleep 1
|
|
bench_one "python3 -m http.server (1 KB file)" 8080 /bench
|
|
kill "$PID" 2>/dev/null; wait "$PID" 2>/dev/null
|
|
sleep 0.3
|
|
|
|
# ── busybox httpd ──
|
|
busybox httpd -f -p 127.0.0.1:8080 -h "$STATIC_DIR" > /dev/null 2>&1 &
|
|
PID=$!
|
|
sleep 0.5
|
|
bench_one "busybox httpd (1 KB file)" 8080 /bench
|
|
kill "$PID" 2>/dev/null; wait "$PID" 2>/dev/null
|
|
|
|
echo
|
|
echo "═══════════════════════════════════════════════════════════════"
|
|
echo "Binary sizes"
|
|
echo "═══════════════════════════════════════════════════════════════"
|
|
printf " uncommonlisp asm: %s\n" "$(du -b asm/uncommonlisp | cut -f1) bytes"
|
|
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)"
|