Performance notes

On this page

A summary of what has been measured, with links to the records. All runs are on the owner's Apple M4 Pro (12 cores) over loopback, with the load client on the same machine and often other builds running, so treat the numbers as relative, not absolute. Each record lists its load average and method; the rules for recording are in benchmarks/README.md.

TopicResultRecord
Static files, keep-alive HTTP/1.1About 93k req/s at 16 connections and 97k at 64; second to lighttpd, 14–20% ahead of nginx, ahead of h2o, Apache and CaddySERVER-COMPARISON, compare-servers-final
New connectionsAbout 21.9k/s on the BSD socket listener vs nginx's 18.0k; Network.framework TCP manages about 2.3k/s, which is why cleartext uses BSD socketsM3-accept
HTTPSAbout 44.6k req/s keep-alive (TLS 1.3 on Network.framework), about a third below cleartext over NWM5-tls, M5-listeners
HTTP/2374,655 req/s with h2load -c 16 -m 10 (in-memory body) vs nginx h2c's 135,367; h2spec 146/146M13-h2
Large filessendfile(2): about 9 GB/s for a cached 512 MiB file; a 1 GiB download keeps RSS flat near 8 MiBSERVER-COMPARISON
Per-request CPUHead parse of 10 headers about 133 ns, serialize under 100 ns, zero allocations; a static-file cache hit about 75 nsM-final-micro, M3-micro
ComponentsAn unregistered component costs nothing; a disabled if component about 2 ns; access log and metrics tens of ns; router matching allocation-freeM4.1-components, M6-accesslog, M6-router, M6-vhosts-auth
CompressionLevel 4 gzip compresses HTML to about Brotli's size at about half level 6's CPU; static variants are compressed onceM6-compression
Reverse proxyAdds about 18 µs per request over a warm pool; on par with Apache mod_proxy one request at a time (11.6k vs 11.1k req/s), 10–20% behind Apache and nginx under concurrencyM17-proxy
WebSocketspermessage-deflate ratio and CPU per messageM15-websockets
HTTP/3Priorities and the QPACK dynamic table measured; throughput is bounded by Network.framework's per-stream cost (about 590 allocations and 0.4–0.8 ms per stream)M10-priorities, M10-qpack-dynamic, QUIC spike

What this means for configuration

Tried and dropped: SIMD and Accelerate

SIMD scanning made WebSocket UTF-8 validation about 3x faster and small-frame unmasking about 2x faster, but it didn't change requests per second: the server's own code is about 0.3 µs of a roughly 22 µs request. Accelerate has nothing for byte parsing. The experiment wasn't merged; the measurements are in ../notes/simd-accelerate.md.

Measuring yourself

swift build -c release -j 2 --product sws-bench
.build/release/sws-bench micro --filter StaticFiles       # ns and allocations per operation
scripts/guarded.sh -t 2400 -- scripts/bench-compare.sh 10 /tmp/compare.md   # vs nginx etc. (needs them installed)
scripts/guarded.sh -t 600 -- scripts/bench-proxy.sh 5 1 16 64               # proxy vs Apache and nginx

Record the load average with every result, and run on an idle machine before quoting numbers.