ubuntips

Centrifugo: the release binary or a source build

Draft posted on · 5 min read

On this page
Draft commented on Dec 2, 2026

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:

  • GOAMD64 levels. The release is built for v1, the baseline every x86-64 CPU runs. v3 lets the compiler assume AVX2-class instructions, which is the nearest Go gets to -march=native.
  • Go PGO. The compiler can take a CPU profile from a real workload and optimize the hot paths, roughly what PGO does for PHP.

v3 is 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:

  • Same source. Centrifugo v6.10.4 from GitHub’s archive of the tag. The archive is accepted only if its tree equals git archive of the same tag from a clone whose tag commit matches the remote. An archive isn’t byte-stable over time, but its tree is.
  • Same Go. The version the tag’s own release workflow builds with, Go 1.27.4, downloaded from go.dev and accepted only if it matches the SHA-256 go.dev publishes for it.
  • Same flags. The upstream ldflags, CGO off, -trimpath.
  • Two arms. src-v1 uses GOAMD64=v1 like the release. src-v3 uses GOAMD64=v3. With src-v1 in the run, a gap between the release and src-v3 could 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-v1 is 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#

Arm4,000 sockets p50 / p9910,000 sockets p50 / p99Centrifugo CPU at 10,000
release2.5 / 4.7 ms (round 2; round 1 p99 14.9 ms)37 / 46-50 ms0.73-0.74 cores
src-v12.5 / 4.7 ms35-36 / 45-46 ms0.73 cores
src-v32.5 / 4.7 ms37 / 46 ms0.73 cores

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-v1 has 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:

  • A Go toolchain. The script would have to download, verify and keep Go current, next to the clang it already maintains, only to build one service.
  • A build that can fail. Fetching modules and compiling at install time is one more step that can break during an --optimize run.
  • Losing upstream’s verification. The release binary is checked against 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 --centrifugo keeps 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 v3 result. 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#

  • Go PGO, as above.
  • AMD. Everything ran on the Xeon. Nothing ran on the AMD EPYC 7401P (Zen 1) server.
  • More rounds. Two clean rounds per arm show that nothing large is there. They can’t resolve a difference of a few percent.
  • Load generator on a separate host. It shared the CPUs with Centrifugo, as in the earlier tests, which inflates the 10,000-socket numbers for every arm.
  • Beyond 10,000 sockets. That covers my largest boards at peak. A much bigger load could show a difference these runs can’t.

Back to top ↑