Skip to content

fix(autotune): clamp instead of killing PID 1 when a profile does not fit (#133) - #134

Merged
sylvesterdamgaard merged 1 commit into
mainfrom
fix/autotune-clamp-133
Sep 4, 2026
Merged

fix(autotune): clamp instead of killing PID 1 when a profile does not fit (#133)#134
sylvesterdamgaard merged 1 commit into
mainfrom
fix/autotune-clamp-133

Conversation

@sylvesterdamgaard

Copy link
Copy Markdown
Contributor

Fixes #133 — the boot PHP-FPM calculator exited PID 1 when the memory limit could not fit the profile, crash-looping any image with a baked default profile (e.g. PHP_FPM_AUTOTUNE_PROFILE=medium) below ~512MB.

Change

  • Clamp, don't die (default). One shared memory model (sizeWorkers) picks the largest worker count that fits; the profile minimum is now a preference, not a hard floor that can OOM. Too small → clamp (down to 1 worker, over-committed with a loud WARN) and boot. Calculate() errors only in strict mode.
  • global.autotune_strict (env PHP_FPM_AUTOTUNE_STRICT), default false. True keeps fail-hard, with a message naming the profile and the smallest limit that runs it.
  • One shared minimum (smallestBootableLimit): the pre-check number equals a limit that actually boots (they used to disagree).
  • Docs + CHANGELOG; the memory refusal is gone from validateConfig (sizing owns memory now).

Acceptance criteria (#133)

  • Derived/default profile that does not fit clamps with a WARN, not os.Exit(1)
  • Explicit misfit honours the autotune_strict toggle, documented
  • Pre-check minimum equals the smallest limit that actually boots
  • The message names the profile and the smallest working limit

Verified

Full gate green (fmt, vet, lint, race tests, updated + new clamp/strict unit tests). End-to-end in a php:8.4-fpm container:

  • --memory=256m + medium (the crash-loop case): boots, clamped to 1 worker, /proc/1/comm = cbox-init.
  • same, PHP_FPM_AUTOTUNE_STRICT=1: exits 1 with profile "Medium Production" needs at least 488MB for its 4-worker minimum, but the limit is 256MB; ... set global.autotune_strict: false to clamp and boot.

… fit (#133)

The boot PHP-FPM calculator exited PID 1 when the container's memory limit could
not fit the selected profile, so any image with a baked default profile (for
example PHP_FPM_AUTOTUNE_PROFILE=medium) crash-looped at boot below ~512MB.

Since 3.1 the boot value is only the seed for the embedded runtime autotuner, so
refusing to start is the wrong failure mode. The calculator now sizes through one
shared memory model that clamps to the largest worker count that fits (down to one
worker, over-committed with a loud warning on a pathologically small box) and
boots, rather than erroring. A new global.autotune_strict (env
PHP_FPM_AUTOTUNE_STRICT) keeps the fail-hard behaviour for operators who want a
hard guarantee; its error names the profile and the smallest limit that runs it.

The pre-check minimum and the sizing now share smallestBootableLimit, so the
reported minimum is a limit that actually boots (the two used to disagree, which
made the refusal message confusing).

Verified end to end: a --memory=256m medium container boots (clamped) instead of
exiting 1, and fails clearly under strict mode.

Closes #133
@sylvesterdamgaard
sylvesterdamgaard merged commit e4b70ea into main Sep 4, 2026
9 checks passed
@sylvesterdamgaard
sylvesterdamgaard deleted the fix/autotune-clamp-133 branch September 4, 2026 20:02
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.

Boot autotune kills PID 1 when the profile floor exceeds the memory limit — clamp instead, and the pre-check minimums understate the real floors

1 participant