Related posts
- 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.
- XenForo on Valkey: do you need php-redis?
Six XenForo cache setups, 300 load-test runs, MariaDB local and simulated remote. The PHP extension barely matters; the cache itself does.
- Setup script 1.22.5, before and after: XenForo 17-32 % faster on the same box
I benchmarked the whole 1.22.5 release against 1.22.4 the way a server gets it: an --optimize run, a reboot, then load. Cached XenForo pages went from 122k to 161k req/s, uncached pages 17-22 % faster, p99 14-20 % lower, and PHP-FPM uses half the memory. Most of it is the kernel; the rest is a new allocator for PHP, a lower Brotli level and AWS-LC under nginx. The benchmark also caught a bug that would have stopped every updated server from rebuilding PHP.
My setup script spent the last two weeks carrying a one-time migration: the code that moved a 1.21 server from Angie to a compiled nginx, from Sury’s PHP packages to a source build, and from a packaged Redis or Valkey to the compiled Valkey (how that went). Every server I run has now been through it. This cycle removed it, and used the same test runs to look for new speed in nginx, PHP, Valkey, MariaDB and Elasticsearch.
Deleting code that live servers might still need#
Migration code is easy to write and hard to delete: the day you delete it, any server that did not finish the migration is stranded with a script that no longer understands it. So the removal came in two parts.
A guard first. Before any mode runs, setup.sh now checks for a 1.21 state: an unfinished migration record, the temporary
policy-rc.dthe migration installs, a 1.21 build trigger, Angie still serving, or a packaged PHP-FPM, Valkey or Redis still serving on a host that shows signs of 1.21 (Sury packages, an Angie directory) and never started the migration. Any of these stops the run with one message: check out v1.22.35, the last release that carries the migration, and run--optimizewith it.--purgeand--diagnosticsstill run on such a host.The first draft of that guard was wrong in two instructive ways, and an independent review caught both. It refused hosts that had finished the migration on purpose with a package still serving (the migration leaves a small host on its packaged Redis below the 4 GB class). And its warning about packages left installed but stopped suggested
apt-get purge, which on these hosts deletes configuration and data directories the source builds still read. A “helpful” cleanup hint in a refusal message is still a command someone will copy. A final review before the release caught a third: every setup.sh run creates its state directory, so the first draft would also have refused, from its second run on, a host that was never on 1.21 but happened to run Ubuntu’s own php-fpm. The guard now asks for evidence of 1.21, not just for a package.Then a read-only look at every server. Part of the old code did not belong to the migration itself but to leftovers it might have left behind: an Anubis bot-filter unit, Angie’s ACME client stanza, a Brotli/zstd
load_moduleline, a PHPupdate-alternativesgroup, a Sury diversion of/usr/bin/php, an old allocator recorded in a PHP build. Each of those clean-ups can only go once no server has the leftover. So instead of guessing, a script ran the new guard’s own function plus one check per leftover on all 22 servers, as root but writing nothing.Every server passed the guard. Eight of the ten leftover checks were clean everywhere, so that code went. Two were not: seven migrated servers never recorded that a PHP extension clean-up had finished, and two still carry a list of extensions to drop. Those two helpers stay for another release. The check also turned up one server that had only ever had a 1.20
--basicrun and one that setup.sh never managed at all, both worth knowing about before pointing a new release at them.In total about 14,200 lines left the repository and 2,300 came in (mostly the guard, its tests and the query-cache work below). The proof that nothing else changed is a parity test on the test box: a fresh install of the new code against a fresh install of 1.22.35, and
--optimizewith the new code on a 1.22.35 server. Both compared/etc, the systemd units,nginx -T,php -i, the PHP-FPM pools, every Valkey setting, every MariaDB variable, sysctl and the crontab. The only differences were the query cache, a timestamp Elasticsearch’s package writes into its own configuration, and counters.Nine ideas, one winner#
The test box is a Xeon E-2236 (6 cores, 12 threads, 62 GB, NVMe RAID0) on Ubuntu 26.04 with a XenForo 2.3.13 forum seeded with 20,000 members, 10,000 threads and 100,000 posts: PHP 8.5 from source, MariaDB 11.8, sessions and cache in Valkey, search on Elasticsearch. Every idea ran as an interleaved A/B: the two arms alternate inside each round, six rounds, CPU clock pinned at 3.6 GHz so turbo cannot reward whichever arm runs after an idle gap. The bar for a new default is the same as always: at least 2 % faster on some page type and slower on none.
always)SCHED_BATCHzend.enable_gc=0)Why the query cache wins here#
The query cache has a bad reputation, and mostly an earned one: one global lock, and every write to a table throws away every cached result that read it. MySQL removed it in 8.0. MariaDB kept it, and the setup script had it switched off since long before 1.22.
On this forum it comes out well ahead, and the reason is visible in the cache itself. XenForo asks the same small set of questions on every page: options, style and phrase lookups, permission caches, node lists, the online-user count. About 35 distinct queries end up cached, in less than 1 MB, and they are hit about 245,000 times per benchmark round. Those queries read tables that change rarely. Posting a reply writes to the post, thread and user tables, which drops the handful of cached results that read them, and leaves the rest alone.
That is why the gain survived the two tests designed to break it. A background writer posting two replies a second (1,859 posts during the run) kept it at 9-12 %. Quadrupling the PHP workers to 48 with 200 concurrent connections, to put pressure on the global lock, still left 7.5-10 %.
The cache is sized from RAM, not set to a fixed 64 MB: RAM/1024, rounded down to 8 MB steps and kept between 16 and 64 MB (56 MB on this box). A bigger cache only makes invalidation slower.
--optimizeswitches it on withSET GLOBAL, so no MariaDB restart is needed.SETUP_MARIADB_QUERY_CACHE=0keeps it off for a workload where it does not fit, such as a write-heavy site that keeps a few hot tables changing.Before and after#
The release against 1.22.35, same box, same forum data, median of five rounds:
The cached guest page never reaches PHP or MariaDB, so it does not move. Everything PHP renders got about a tenth faster, with the slowest requests improving most.
Why the losers lost#
SCHED_BATCHand multi-size huge pages measured inside the noise. Both are cheap to apply, which is exactly why they need the 2 % bar: a default that changes nothing still costs a line of code and a line in every report.What this does not prove#
All of it ran on one Intel box; the AMD test machine is gone. Most of my database servers run MariaDB 10.11 (Ubuntu 24.04), and the gain was measured on 11.8. The query cache code is old and stable in both, so I expect the gain to carry over, but I have not measured it there.
What I could check is the switch itself. Update: the first live server to get the release runs MariaDB 10.11.14, started with the cache off.
--optimizeswitched it on withSET GLOBAL(OFF to 56 MB) in a 21-second run, with the same MariaDB process before and after and no service restarted; a probe of the site saw only 200s, and a minute later the cache had served its first 215 hits. Had a server refused the change, the value would simply wait for its next restart:--optimizenever forces one for it, retries the live switch on every run and says in its report when the cache is configured but still off on the running server.