Related posts
- Compiling Valkey, and the BOLT flag that gave my binaries an executable stack
Valkey from source was 35 % slower until I stopped passing CFLAGS on make's command line. Then its unit refused the BOLTed binary, which exposed an executable stack in my compiled PHP and Angie too. Plus nginx vs Angie, compiled the same way.
- Why my from-source PHP was slower, and the one-line answer: ICU
A from-source php-fpm executed 9 % fewer instructions per page than a clang build using Sury's extensions, yet ran 1-2 % slower. The cause was ICU: the intl extension made the binary 102 MB and multiplied data-TLB misses by 4.5. Without it, the merged build is the fastest: +11 % on logged-in XenForo pages.
- Three php-fpm builds side by side: Sury, clang + BOLT, and everything from source
My earlier compiled-PHP tests found nothing. Two flaws in my build harness were hiding the gain: GCC was built without its global registers, and BOLT was never tried. With both fixed, a BOLT-optimised php-fpm is 5-10 % faster on logged-in XenForo pages. Building every library from upstream as well added nothing measurable.
My setup script compiles Valkey from source and, on a host that can record branch samples, runs it through BOLT: it profiles a benchmark and lays out the hot code again. This cycle had one job: stop
--optimizefrom restarting Valkey more than once.Three restarts where one would do#
An
--optimizerun looks at Valkey in two steps. First the tuner rewritesvalkey.conf. Some of what it sets only applies at startup, such as the socket permissions, so when one of those changes the tuner restarts the server. Then the build step brings the binary up to date. If upstream released a new Valkey, it activates the new build, which is a second restart. If the build has not been through BOLT yet, it profiles it and swaps in the optimized binary: a third restart.Every one of these restarts makes Valkey write its RDB snapshot and load it again. That keeps the cache and the sessions across the restart, but on a busy forum with a large cache it is the slow part, and during it PHP cannot reach its cache.
Fresh installs had the same pattern in a different order: the server started, was restarted 20 seconds later for BOLT, and again five seconds after that, when the installer wrote
valkey.conf.Why BOLT never needed the live server#
The fix comes from one detail. The BOLT profile does not come from the production server: since 1.22.5 the tool boots a private, throwaway Valkey from the new build on its own socket, drives it with
valkey-benchmark, and builds the optimized binary from that profile. The live server only ever needs the final binary.So when a BOLT pass is due, the tuner and the build activation no longer restart anything. They write their changes, record that a restart is pending, and leave it to the BOLT swap, which restarts once and picks up the configuration, the new build and the optimized binary together. When BOLT cannot swap (no branch samples on a VM, too few samples), a new
restartcommand does the one restart instead.A fresh install now installs and BOLTs the build while the unit is still down, writes the configuration, and only then starts Valkey, once.
What could go wrong, and what now happens#
Folding restarts moves risk around. Two independent reviews of the change tried to break it, and two findings mattered:
valkey.confdid not start, the folded restart would have fallen back from the BOLT binary to the plain build, then to the previous release: four or five failing restarts, about 30 seconds each, before the configuration came back. Now the configuration is put back first and the new binaries stay. Only if the old configuration fails too does the binary fall back.Measured#
One box: the Xeon E-2236 (6 cores, 12 threads, 62 GB, NVMe RAID0) with Ubuntu 26.04, a XenForo 2.3.13 forum seeded with 20,000 members, 10,000 threads and 100,000 posts, sessions and the XenForo cache in Valkey, search on Elasticsearch. While
--optimizeran underwrkload, a probe pinged the Valkey socket every 20 ms and logged every outage, every process ID change and every systemd start.No key was lost in any run. Each restart costs only about 0.2 seconds here because this test cache is small. On a production cache each one also writes and reloads the whole snapshot, so the saving grows with the data.
The fresh install went from one start and two restarts to one start. An
--optimizestraight after it changed no file and restarted nothing, so a new server and an optimized one end in the same state.Throughput did not move#
The change only reorders work that happens during setup, so request speed should not change, and the rule of the project is that nothing may get slower. Five rounds per tier, clock pinned at 3.6 GHz:
The first baseline of the day had been about 1.5 % faster on the uncached tiers than the new release. That is under my 3 % noise line, but the ranges did not overlap, so I checked rather than shrugged: I ran the old release’s
--optimizeon the new state. It changed no file and no binary, and the run measured right after it matched the new release. The two releases build the same server; the box itself had drifted in between (view counters, a rebuilt cache), and the table above compares them on the same state.What is left#
One case still restarts twice: an
--optimizewith no BOLT pass to make, where the tuner needs a restart and a new release also changed the systemd unit. That one goes on the list for the next cycle.