Internals: benchmark reports

ScalPanel edge features on the proxy path, against nginx (2026-11-18)

The benchmark gate of the 1.1 edge-features plan (Task 15, ruling C2): what the keys ScalPanel’s generator puts on a website route cost on the proxy path, and how ScalWS with them compares with nginx configured the same way. Gate: (b) within 3 % of (a) per row, at 1 and 6 CPUs.

Result: the gate is not met. After two fixes and a PGO training change found by profiling (below), (b) is at 0.857 and 0.889 of (a) at 1 CPU and 0.938 and 0.974 at 6 CPUs: one of four rows passes. The edge keys cost about 8 us of CPU per request on this host (52 to 60 us). nginx pays more for the same directives (0.88 to 0.93 of its own (a)), and ScalWS with the edge keys is 1.07x to 1.18x nginx with them in every row.

Verdict (controller, 2026-11-18): the 3 % miss is accepted for 1.1. The binding rule is at least 1.05x nginx in every scenario at 1 and 6 CPUs, which (a) and (b) meet. Deferred to 1.2: header operations without hashing custom names on every request, a one-pass cookie strip and a lighter access log record path (the items of the bisection below). The 1 KiB rows of (c) were under 1.05x nginx and were fixed in this task: see “Follow-up: gzip of small known bodies”. The PGO training overlap (fix 2 below) is accepted and disclosed.

Method

bench/edge.sh <scalwsd> <scalws-bench-upstream> <out-dir> (the script’s header has every detail).

  • Host: xeon, 2x Xeon E5-2650 v2 (no AVX2), Ubuntu 26.04, kernel 7.0.0-38, performance governor. Server on CPU 0 (1 CPU) or 0-5 (6 CPUs), socket 0; the bench upstream on 6, 7, 22, 23; oha 1.16.0 on 8-15 and 24-31 (socket 1), 64 connections, 5 s warm-up and 15 s measured per row, 3 rounds with the server order rotated; medians, ratios are the median of the per-round ratios. CPU us/req: user + system time of the server’s process tree during the measured window over the answered requests.
  • Route: the website route of ScalPanel’s edge sample (tests/integration/fixtures/scalpanel-edge/edge.yaml, application r0-0, prefix route /, with the regex hotlink route and the two webmail redirects before it, route_order: nginx), the upstream replaced by the bench upstream, which answers /edge/1k.txt (1 KiB text/plain) and /edge/20k.css (20 KiB text/css, compresses about 3.8x with gzip level 1). Kept from the sample in every variant: limits, trusted_proxies, max_body, preserve_host, websocket, timeouts. Left out: the https and probe listeners and https_redirect (plain HTTP is measured), and server.security.per_ip (50 requests per second per client would answer 429).
  • Every request: Host: www.example.com, Accept-Encoding: gzip, Cookie: wp-settings-1=...; vpwm_session=...; theme=dark (so remove_cookies removes a cookie in the middle of the line).
  • (a) the route without the edge keys. (b) as generated: deny (2 networks), deny_networks: [CN] with a 300 000-line CN file, remove_cookies, request_headers.set (3 headers), response_headers.remove (5 headers), forwarded_for: client, application access_log with format: scalpanel. (c) (b) plus the sample’s server.compression (gzip, streamed at level 1).
  • The CN file: the sample’s two networks, 269 998 IPv4 networks in [redacted address] (/32, /31 and /30 in turn) and 30 000 IPv6 /56s in 2001:db8::/32, none adjacent (nothing merges). The client (127.0.0.1) is in no deny list. The network set is a file set, as in the sample; a GeoIP countries set is not measured (the client would be loopback, which is never looked up).
  • nginx 1.31.6 (no 1.30 build on xeon; 1.31.6 is the release every 1.0 and 1.1 ratio was taken against) with bench/configs/nginx-edge.conf: the same locations; for (b) deny, a geo of the same 300 000 networks with if ($edge_cn) { return 403; }, a map that removes vpwm_session from $http_cookie, proxy_set_header for the set headers, X-Forwarded-For $remote_addr and X-Real-IP, proxy_hide_header for the removed ones, log_format scalpanel (ScalPanel’s) with access_log ... buffer=64k flush=1s; for (c) gzip on, level 1, gzip_min_length 1024, the sample’s types, gzip_proxied any.
  • Before the rounds the script checks every server: 200 with the expected size and encoding, the access log written, and a copy of the CN file with 127.0.0.1/32 added answering 403 (ScalWS and nginx alike). Every run answered 2xx only.
  • During every run a sampler recorded the load and any cargo or rustc process every 10 s: none ran during run 1 or run 2 (other agents’ builds ran between runs; runs were started only after 60 s without one).

Runs

runwhen (UTC)scalwsd commitscalwsd sha256upstream sha256what
011:14-11:16d8b13b33039a25d5a6b01acbace5b7a74d2e48c72a3ffcf967422f70d1b559e613dcebbc4cfea89ab1bfbbee7d3b5ebe960e0fea4a18f24b287147f157bab131ebf5ec8csmoke (1 round of 2 s), profile, per-feature bisection
111:47-12:13cdf4449075be57ac5a1cb50c64272d4a412ffe7d4b1a6cdf84fcabf6b85f180a6cf79e8e4cfea89a…full run after fix 1
213:31-13:570e2bb10a (tools f64efcb9)bfbce83d2ebaa1b3eb27e563d6f84027bdd8c8fcdf56bc23dd6e2ec69fc50e654cfea89a…full run after fixes 2 and 3 (reported)

All tools/pgo-build.sh with PGO_FEATURES=scalwsd/http3. Upstream: scalws-bench-upstream of this commit (the /edge/ bodies), built release.

Results (run 2)

(b) edge keys against (a) without them (gate: >= 0.97)

CPUsscenario(b) rps(a) rpsratio (median, min-max)(b) p99 ms(a) p99 ms(b) CPU us/req(a) CPU us/reqgate
1proxy-1k16679193030.857 (0.837-0.867)4.173.6360.051.8FAIL
1proxy-20k-css13356150280.889 (0.874-0.927)5.124.5974.966.5FAIL
6proxy-1k952211021170.938 (0.906-0.940)0.890.9663.058.1FAIL
6proxy-20k-css75476775180.974 (0.964-0.980)1.271.3078.774.0PASS

(c) edge keys and gzip against (a)

CPUsscenario(c) rps(a) rpsratio(c) CPU us/reqbytes/resp
1proxy-1k10324193030.535 (0.529-0.537)96.9499
1proxy-20k-css5903150280.396 (0.388-0.396)169.55394
6proxy-1k595591021170.585 (0.580-0.587)100.6499
6proxy-20k-css34380775180.442 (0.442-0.446)174.45394

Against nginx (ScalWS rps / nginx rps, median of the per-round ratios)

CPUsscenario(a)(b)(c)nginx (b) / nginx (a)
1proxy-1k1.1451.1030.9410.901
1proxy-20k-css1.2221.1771.4310.934
6proxy-1k1.0331.0650.9000.882
6proxy-20k-css1.0641.1251.3990.915

nginx rps: (a) 16787, 12341, 98660, 72763; (b) 15124, 11524, 87502, 66607; (c) 10968, 4125, 66202, 24543 (rows in the order above). nginx’s gzip sends 378 and 4035 bytes, ScalWS’s 499 and 5394 (both level 1; nginx shrinks its window and memory level to the known body length, which is also why nginx is ahead at 1 KiB in (c)).

Profile, fixes and what is left

Run 0 (d8b13b33): (b) was 0.62x to 0.68x (a) at 1 CPU. perf record on CPU 0 and a bisection (each edge key dropped from (b) in turn, 1 CPU, 2 rounds) put about 24 us of the 30 us per request on the access log and 6 us on request_headers; deny, the network set, response_headers and forwarded_for measured at noise level.

  1. Access log writer (cdf44490). The writer thread did one write(2) per line and the event loop woke it (a futex system call and a context switch on the same CPU) for almost every line: the scalws-log thread alone took 10 % of CPU 0. Now the lines queued for a file go out in one write (up to 64 KiB, whole lines; a short write still counts the lines it cut as dropped) and the writer waits 10 ms after a batch, so under load the loops seldom wake it. Lines reach the file at most about 10 ms later (docs/guide/logging-metrics.md). Tests: interleaved lines of two files over more than one write stay whole and in order; the line count after a short write. Run 1: (b) 0.83x to 0.94x (a).
  2. PGO training (f64efcb9). The training load of tools/pgo-build.sh had no edge keys, so their code was laid out cold: in the run 1 profile strip_cookies, HeaderOps::apply, HeaderMap inserts and the network lookup cost several times what they do. The training now runs a ScalPanel edge website (deny, a 20 000-network set, cookie removal, header changes, forwarded_for, a scalpanel access log, gzip of proxied text, a refused referer). Note: two of its requests (/edge/1k.txt, /edge/20k.css with gzip) are the ones this bench measures; every other row of the training is unchanged. It also made (c) faster (20 KiB at 1 CPU 4691 to 5903 rps).
  3. scalpanel line (0e2bb10a): numbers and the IPv4 address formatted by hand instead of core::fmt (about 0.9 us per request in the run 1 profile). Test added.

What is left (run 2 binary, bisection at 1 CPU, 1 KiB, 3 rounds; CPU us/req of (b) with one key dropped, against (a) of the same run; (b) costs about 7.5 us over (a)):

dropped from (b)(b) minus key, us/req(a)over (a)so the key costs about
access_log57.152.64.53 us
request_headers (cookie removal, 3 sets)57.051.25.82 us
forwarded_for58.852.56.31 us
deny, deny_networks, server.networks59.452.17.30.5 us or less
response_headers (5 removes)59.752.07.7noise

The profile of run 2’s binary spreads the rest over strip_cookies and HeaderOps::apply (about 1.2 us together: hashing custom header names for 3 inserts and 5 removes, two passes over the cookie line), the log line and its record (AccessLog emit and drop, about 0.7 us), the network lookup in 300 000 ranges (about 0.4 us) and a wide tail of a few tenths each. The gate allows 1.6 us per request at 1 CPU on this host: no single remaining item is large enough, and together they are about five times the budget. At 6 CPUs the same cost is a smaller share (the loops also wait on the network), hence 0.938 and 0.974.

Follow-up: gzip of small known bodies

Run 2 left (c) at 1 KiB under the 1.05x nginx rule: 0.941 at 1 CPU and 0.900 at 6. Each streamed gzip response built a new flate2 GzEncoder: zlib-rs allocates and clears its full 2^15 window state (about 370 KiB with the fixed 64 Ki-entry hash table) and GzEncoder adds a 32 KiB buffer, for a body of 1 KiB. nginx sizes the window and memLevel down to a known Content-Length.

The backend is zlib-rs through flate2 1.1.10 (features = ["zlib-rs"]), which offers window bits 9 to 15 for raw deflate (Compress::new_with_window_bits) but no memLevel (and zlib-rs’s hash table has a fixed size whatever memLevel is). The change (185a93c4):

  • gzip framing (header, CRC-32, length) is written by ScalWS around raw deflate, so the window can be chosen; without a length the bytes are GzEncoder’s exactly (test), so cached variants keep their bytes under the same strong ETag.
  • With a known length (Content-Length or an exact body size) the window is halved while the body plus 262 bytes fits in half of it, down to 2^9, as nginx does. A body of unknown length keeps 2^15 (test).
  • At the streaming level, finished states with windows of 2^9 to 2^12 (bodies under 3834 bytes) are kept, one per window size and thread, and reset for the next small response instead of allocated and cleared again (at most 4 states per event loop thread).
  • Tests: round trip for sizes around every window threshold (0 to 70 000 bytes, chunked, with a flush), with and without a length; a reused state gives the same bytes as a new one; byte equality with GzEncoder without a length, at both levels. A microbenchmark of 1 KiB (Windows, not a gate): GzEncoder 11.1 us, raw deflate 2^15 3.6 us, 2^11 2.8 us, reused 2^11 1.4 us.

Measured on xeon (same method, SERVERS="scalws-a scalws-c nginx-c"), PGO builds:

runscalwsd commitscalwsd sha256(c) / nginx, 1 KiB, 1 CPU6 CPUs20 KiB, 1 CPU6 CPUs
run 2 (before)0e2bb10abfbce83d…0.9410.9001.4311.399
edge3: sized window onlyworking tree5231ff4547bdd9a29f50d86c98cdca4f892432f93885a738d2a04f07856ae5ff1.045 (1.039-1.056)1.000 (0.986-1.030)1.4411.437
edge4: sized window and reuse185a93c4a1e537f8c43d7c494856fcf541c46a4725db689d7293c82b3ebeafc3306890eb1.084 (1.052-1.120)1.088 (1.074-1.092)1.4141.452

edge4 in rps: (c) 12113 against nginx 11171 at 1 CPU, 72212 against 66368 at 6 CPUs (1 KiB); 5782 against 4090 and 35352 against 24355 (20 KiB); CPU per 1 KiB response 82.6 us against nginx’s 89.5 (run 2: 96.9). Bytes are unchanged (499 and 5394; nginx 378 and 4035: zlib-rs’s level 1 is zlib-ng’s faster “quick” strategy). During edge4 the sampler saw a concurrent cargo for 40 s of the 12 minutes (one stretch, 15:28 to 15:29 UTC); the round spread of the 1 KiB rows stays above 1.05 in every round, and (a) and nginx match edge3 within 1 %.

Compression rows of docs/benchmarks/2026-11-15-compression.md this change touches, with edge4’s binary (no cargo or rustc during either run):

row2026-11-15now
(c) mode all, 50 KiB PHP gzip, 1 CPU, against nginx1.5501.682 (1.675-1.691)
(c) same, 6 CPUs1.7611.871 (1.649-1.976)
(f) background p99 with gzip fills, against off (lower is better)1.8091.759 (1.668-1.856)
(f) gzip fill load, rps299308

No regression (the gains include the PGO training of fix 2). The brotli rows of (f) do not use this code; they measured 2.529 against 2.264 for the background p99, inside the spread that part has shown before (2.247 to 2.553). The (b) static rows serve cached variants, whose bytes are unchanged.

Reproduce

# also builds the bench upstream (target/pgo/plain)
PGO_FEATURES=scalwsd/http3 tools/pgo-build.sh
bench/edge.sh target/pgo/scalwsd target/pgo/plain/release/scalws-bench-upstream /tmp/edge
# one variant only, with a profile of the server CPUs:
SERVERS="scalws-a scalws-b" LAYOUTS=1:0 PERF="-F 1999" bench/edge.sh ...