Skip to content

feat(fpm-tune): expose cpu_ceiling + cpu_headroom in the embedded runtime - #142

Merged
sylvesterdamgaard merged 1 commit into
mainfrom
feat/fpm-tune-cpu-ceiling
Sep 8, 2026
Merged

feat(fpm-tune): expose cpu_ceiling + cpu_headroom in the embedded runtime#142
sylvesterdamgaard merged 1 commit into
mainfrom
feat/fpm-tune-cpu-ceiling

Conversation

@sylvesterdamgaard

Copy link
Copy Markdown
Contributor

The embedded tuner sizes pools to the memory budget. On CPU-bound workloads that oversubscribes the CPU: on a 2-CPU/1 GiB container running a pure-CPU request (6k chained sha256 rounds, wrk -t4 -c64), throughput falls monotonically with worker count —

workers 2 4 6 8 12 21
rps 403 394 383 370 311 310

The memory budget picked 21 workers (310 rps). The CPU fill × fpm-tune's default 2.0 headroom picks 4 (394 rps, +27%).

fpm-tune has always had the mechanism (standalone --cpu, serve.Config.CPUCeiling/CPUHeadroom) — the embedded runtime just never mapped it. This adds fpm_tune.cpu_ceiling + fpm_tune.cpu_headroom (0 = default 2.0), automatically env-overridable as CBOX_INIT_GLOBAL_FPM_TUNE_CPU_CEILING / _CPU_HEADROOM, with validation (negative headroom rejected) and tests for yaml load, env override, and rejection. Example config documents the trade-off.

Verified end-to-end in the php-baseimages benchmark harness: an image with this build, CBOX_FPM_TUNE=true + CBOX_INIT_GLOBAL_FPM_TUNE_CPU_CEILING=true, converges to the CPU-sized pool at runtime. Gate: full tests, vet, gofmt, golangci-lint v2.12.2 0 issues.

…untime

The tuner sizes pools to the memory budget; on CPU-bound workloads that
oversubscribes the CPU and costs throughput. Benchmarked on a 2-CPU / 1 GiB
container running a pure-CPU request (6k chained sha256 rounds), worker
count vs throughput is monotonic downward:

  workers   2     4     6     8     12    21
  rps     403   394   383   370   311   310

The memory budget allowed 21 workers (310 rps); the CPU fill with fpm-tune's
default 2.0 headroom picks 4 (394 rps, +27%).

fpm-tune has always had the mechanism - the standalone --cpu flag and
serve.Config.CPUCeiling/CPUHeadroom - but the embedded runtime never mapped
it. Now: fpm_tune.cpu_ceiling (bool) and fpm_tune.cpu_headroom (float,
0 = fpm-tune default 2.0), env-overridable via the generic
CBOX_INIT_GLOBAL_FPM_TUNE_CPU_CEILING / _CPU_HEADROOM path, negative
headroom rejected by validation. Example config documents the trade.
@sylvesterdamgaard
sylvesterdamgaard merged commit 13c53c7 into main Sep 8, 2026
9 checks passed
@sylvesterdamgaard
sylvesterdamgaard deleted the feat/fpm-tune-cpu-ceiling branch September 8, 2026 21: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.

1 participant