ubuntips

One Valkey restart per run: folding three restarts into the BOLT swap

Draft posted on · 5 min read

On this page
Draft commented on Nov 30, 2026

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 --optimize from restarting Valkey more than once.

Three restarts where one would do#

An --optimize run looks at Valkey in two steps. First the tuner rewrites valkey.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 restart command 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:

  • A bad configuration would have been blamed on the binary. If the new valkey.conf did 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.
  • A deferred restart lived only in memory. An interrupted run would have left the new configuration written but never applied, and the next run would have seen nothing to do. The pending restart is now written to a file together with the process ID of the running server, so the next run applies it. A reboot or a manual restart makes the record stale instead of causing a needless restart.

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 --optimize ran under wrk load, a probe pinged the Valkey socket every 20 ms and logged every outage, every process ID change and every systemd start.

Pending at the runRestarts, beforeRestarts, afterDown, beforeDown, after
Nothing0000
BOLT110.21 s0.24 s
BOLT + configuration210.46 s0.20 s
New build + BOLT + configuration310.70 s0.22 s

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 --optimize straight 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:

Tier (req/s, median)1.22.331.22.34
Guest home, cached117,272113,091-114,866
Guest home, uncached361361-362
Guest thread, uncached382381-383
Member home323323-324
Member thread295297

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 --optimize on 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 --optimize with 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.

Back to top ↑