Related posts
- PGO for php-fpm is now on by default
My setup script now builds php-fpm with clang PGO from a profile it records on the host itself: a short guest crawl of the host's own sites on a temporary php-fpm and nginx. The CLI stays plain, failures keep the running build, and on the Xeon test host the shipped code path gave +1.0 to +1.5 % on every PHP tier on top of BOLT, with none slower.
- Plain, BOLT, PGO or both on an AMD EPYC (Zen 1)
A second run on the Zen 1 machine, with four builds of PHP 8.6.0 and the first run's two caveats fixed. PGO alone was fastest at +6.1 to +8.4 % and won all 20 comparisons. BOLT from plain samples gave +4.3 to +5.0 % on its own but made PGO slower, and the CLI still lost 4.8 % on bench.php, so the CLI gets built without the profile.
- PGO where BOLT cannot run: PHP 8.6 on an AMD EPYC (Zen 1)
My setup script optimises PHP's code layout with BOLT, but BOLT needs branch records that older AMD CPUs such as Zen 1 don't have, so on those machines PHP gets no layout optimisation at all. Profile-guided optimisation trained on XenForo traffic filled the gap: +6 to +9 % requests per second on an EPYC 7401P, with one catch for the PHP CLI.
My setup script compiles nearly everything it serves with. nginx, PHP and Valkey are built from source with
-march=native, LTO and BOLT. When I added Centrifugo, I made it the exception: the script installs the upstream release binary and verifies it, but doesn’t compile it.The obvious question came straight back: if compiling pays for everything else, why not for Centrifugo? This post is the A/B that answers it.
Go has different levers#
Centrifugo is a static Go binary, so my C toolchain recipe doesn’t apply. Go has its own two levers:
GOAMD64levels. The release is built forv1, the baseline every x86-64 CPU runs.v3lets the compiler assume AVX2-class instructions, which is the nearest Go gets to-march=native.v3is the cheap one to test, so I tested it first.The method#
The point was to change only the compiler target and nothing else, so the source builds had to match the release as closely as possible:
git archiveof the same tag from a clone whose tag commit matches the remote. An archive isn’t byte-stable over time, but its tree is.-trimpath.src-v1usesGOAMD64=v1like the release.src-v3usesGOAMD64=v3. Withsrc-v1in the run, a gap between the release andsrc-v3could be split into “my build” and “v3”.The release isn’t reproducible bit for bit, since it embeds its own build time and other values, so
src-v1is the closest control there is.The toolchain and the arms lived outside anything that serves, and a systemd drop-in switched the live unit between binaries. Configuration, hardening and the load ladder were the same as in the load test that set the defaults, on the Xeon E-2236 test host, with the load generator on the same host. The engine was the in-process memory engine, which tied Valkey at 4,000 sockets and did better at 10,000 earlier the same day.
The numbers#
At 4,000 sockets the three arms are identical. The release’s 14.9 ms p99 in round 1 is a single outlier; the same binary did 4.7 ms in round 2, like the others.
At 10,000 sockets
src-v1has a median 1-2 ms lower. That arm is built like the release, so it is not a candidate that could change anything, only a control; its own p50 moved by 1 ms between rounds and the release’s p99 by 4 ms.src-v3, the arm that should gain most, lands on the release’s numbers. CPU is 0.73 cores for every arm, within 0.01 of the release.None of these gaps is beyond run-to-run noise. My rule for a new default is at least 2 % faster somewhere and slower nowhere, and
src-v3, the only real candidate, shows no gain at all against the release.Round 3 is left out#
A third round ran, and every arm in it was worse: more CPU and higher latency across the board, the release and both source builds alike. When all arms move together like that, the host was disturbed, not the binaries. I left the round out instead of averaging it in.
Why the release binary stays#
A source build would cost real things on every server:
--optimizerun.checksums.txt, GitHub’s own digest and, where cosign is installed, the Sigstore bundle. A local build has none of that; it can only be checked against itself.With no measured gain, that trade is easy.
setup.sh --centrifugokeeps installing the verified release binary, and no Go toolchain goes on servers.Go PGO: not measured#
The build script can also make a PGO arm, from a CPU profile taken on a separate loopback instance under the same kind of load. I didn’t build or run it, so I have no number for it.
The reason is the
v3result. Letting the compiler use AVX2 everywhere changed nothing, which suggests Centrifugo at this load isn’t limited by how tightly its Go code is compiled. PGO could still behave differently; I just didn’t spend the time on it. It’s an untested idea, not a rejected one.What I didn’t measure#