Related posts
- kTLS with nginx: 44 % less CPU on big files, and a 200 ms stall
Kernel TLS lets nginx encrypt files with sendfile(). On this server it first did not work at all: a 1 MB file never finished, because of one sysctl my own script sets. Fixed, kTLS cut nginx's CPU on large files by 40-44 % but made small responses 38 % slower. It stays off.
- XenForo on PHP 8.1 to 8.6: the same build six times
Six PHP series compiled with the same clang recipe and the same extensions, one XenForo forum with 100,000 posts, plain nginx, PHP-FPM and MariaDB. PHP 8.5 and 8.6 serve uncached pages 8-11 % faster than 8.1. 8.2, 8.3 and 8.4 tie, and 8.6 adds nothing over 8.5 yet.
- Dropping the packages: compiled nginx, PHP and Valkey, and what the migration tests broke
My setup script now builds nginx, PHP and Valkey from source and installs none of them from packages. Live servers migrate once, on --optimize. Testing that migration and a PHP downgrade chain found eight bugs, including a build log that grew to 1.7 TB. A day later, 1.22.1 dropped pre-compressed static files.
The XenForo post changed only PHP. This one changes only the TLS library under nginx. Everything else stays fixed: nginx 1.31.10, clang 23 with LTO, and the same PCRE2, zlib-ng and Brotli.
Which libraries, and which not#
I skipped three. wolfSSL’s nginx patch stops at 1.28.1. rustls-libssl only swaps the library under a distribution’s dynamically linked nginx, and is still experimental. LibreSSL had nothing to offer here that the others lack.
The build tool can now produce these as side builds:
nginx-build.sh build-arm DIRwithTLS_LIB=aws-lcorboringsslin its config. AWS-LC and BoringSSL are built as static libraries with cmake. A side build never replaces the running nginx.The setup#
Each library ran as its own standalone nginx on spare ports, all from one config that uses only what every library supports:
nginx ran on 8 of the host’s 12 logical CPUs and wrk on the other 4. The test host is the Xeon E-2236, clock pinned at 3.6 GHz, with 5 rounds, the order reversed every other round, and medians reported. No row failed.
Handshakes#
Every request opens a new connection (
Connection: close, 1 KB body):The req/s row mostly measures the client: wrk does its side of every handshake with Ubuntu’s OpenSSL on 4 CPUs, and it runs out first. nginx’s own CPU time is the server-side number, and there the gap is large. AWS-LC and BoringSSL do an ECDSA handshake in half the CPU time OpenSSL needs, with or without the ML-KEM post-quantum share. With RSA the gap shrinks to about 20 %.
OpenSSL 4.1 is 7-9 % cheaper per ECDSA handshake than 3.5. It also finishes its side faster, so the same client completes 10-12 % more handshakes per second against it.
Keep-alive and bulk#
Once the connection is up, they tie. Every difference sits inside the run-to-run spread, and the client is again the limit at about 4 GB/s. AWS-LC and BoringSSL spend 10-18 % less nginx CPU per byte of AES-GCM.
Why OpenSSL stays#
Half the handshake CPU is a real gain. But it only matters to a server that terminates many fresh TLS connections itself. My servers sit behind Cloudflare, which reuses its connections to each origin, so full handshakes there are rare.
Switching would also cost features:
ssl_conf_command, and no shared session cache, which my nginx config uses.So OpenSSL 4.1 stays the default. It is the fastest OpenSSL here and loses nothing. The other two remain one config line away for benchmarks. A note for my own list: PHP 8.2 to 8.6 currently link OpenSSL 4.1, which is newer than the range php.net supports for its OpenSSL extension (below 4.0). Moving PHP to the 3.5 LTS is a candidate for the next release.
Raw rows and the harness (
tools/nginx-build.sh build-arm,tests/stress-site/tls-arms-bench.sh) are in the setup script’s repository. The next post uses the same harness for kTLS.