Skip to content

fix(php-fpm): let autotune size the spare servers, clamp manual sizing - #57

Merged
sylvesterdamgaard merged 2 commits into
mainfrom
fix/fpm-autotune-clamp
Oct 22, 2026
Merged

sylvesterdamgaard merged 2 commits into
mainfrom
fix/fpm-autotune-clamp

Conversation

@sylvesterdamgaard

Copy link
Copy Markdown
Contributor

TLDR: php-fpm crash-looped in any container where autotune picked fewer than 6 workers (e.g. a 512Mi pod). Fixed in the entrypoint library. cboxdk/init needs no change.

What broke. On cbox-hel1, a 512Mi pod (Reverb on php-fpm-nginx:8.4-bookworm) failed with:
pm.min_spare_servers(1) and pm.max_spare_servers(6) cannot be greater than pm.max_children(4), exit 78. docker run -m 256m or -m 512m reproduces it on the published images.

Why. cbox-init's boot autotune does its job: at 512m it exports max_children=4 with spare counts 2/1/2. But it runs after the entrypoint, which had already written the defaults (2/1/6) into zz-pm-mode.conf as literal numbers. pm.max_children is still a ${…} placeholder in the pool file, so it picked up the tuned value. The spare counts didn't. This came in with 571b696.

Fix

  • The dynamic drop-in is written with ${PHP_FPM_*} placeholders again, the same as the baked pm-mode-dynamic.conf. FPM now reads all four tuned values.
  • Manual sizing: PHP_FPM_MAX_CHILDREN turns autotune off and used to leave max_spare at 6. The entrypoint now clamps the spare counts so 1 ≤ min ≤ start ≤ max_spare ≤ max_children, and logs a WARN with the values it used.
  • cboxdk/init's calculator and fpm-tune's writer already keep that order. Nothing to change there.

Why CI missed it. None of the smoke tests set a memory limit, so the medium profile always picked more than 6 workers. They also probe /healthz, which nginx answers without asking php-fpm. New tests/e2e/scenarios/test-memory-limits.sh runs -m 256m, -m 512m, and -m 256m with PHP_FPM_MAX_CHILDREN=2. It probes /fpm-ping and fails if FPM ever rejected its config. It runs in the e2e smoke test and in the pre-promotion smoke test of all 8 php-fpm-nginx tiers. The merge job's sparse checkout now includes the script.

Verified locally (arm64, 8.4)

  • New scenario: 3 failures on the published image, 0 on a php-fpm-nginx build with the fix.
  • 512m: cbox-init tuned max_children=4, FPM started 2 workers.
  • No memory limit and read-only rootfs: both still serve.
  • Existing scenarios plain-php, health-checks, app-processes, env-config: all pass.
  • php-fpm image with PHP_FPM_MAX_CHILDREN=2: clamps to 2/1/2 and starts. Tested with the new lib mounted, because that image takes its lib from php-base.
  • shellcheck, actionlint, env-contract and docs checks: pass.

Not covered: the legacy PHP_FPM_PM_MAX_CHILDREN override (php-fpm-nginx's zz-env-overrides.conf) is still written as a literal and does not turn autotune off. That path was already broken before this PR and this change leaves it as it was.

Merging publishes new image tags: php-base rebuilds on common/** and triggers php-fpm, which triggers php-fpm-nginx.

A container whose memory limit autotuned php-fpm below 6 workers
crash-looped: "pm.min_spare_servers(1) and pm.max_spare_servers(6)
cannot be greater than pm.max_children(4)", exit 78. cbox-init's boot
autotune exports valid values for all four, but it runs after the
entrypoint, which wrote the pre-tune spare defaults into zz-pm-mode.conf
as literals - so only max_children (still a placeholder in the pool
file) took the tuned value.

The dynamic drop-in is written with ${PHP_FPM_*} placeholders again, the
same as the baked one. Manual sizing (PHP_FPM_MAX_CHILDREN, which turns
autotune off) clamps the spare counts to fit max_children and warns.

test-memory-limits.sh runs the image under -m 256m and -m 512m and with
PHP_FPM_MAX_CHILDREN=2, probing /fpm-ping (/healthz never reaches FPM).
It runs in the e2e smoke test and before every php-fpm-nginx tier is
promoted. 3 failures on the published 8.4 image, 0 after.

@cbox-agents cbox-agents Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Talking to Cbox
  • Reply under a finding to ask Cbox about it.
  • /cbox fix in reply to a finding: Cbox fixes it on this pull request's branch, or, when it can't push there, on a new branch whose push waits for a confirm in Cbox.
  • /cbox review reviews this pull request again now.
  • /cbox <question> asks Cbox about this pull request.
  • /cbox help shows this list.

Only people who can push to this repository and have linked their GitHub account in Cbox can use /cbox.

@sylvesterdamgaard
sylvesterdamgaard merged commit eaa4348 into main Oct 22, 2026
112 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant