Skip to content

Make the PHP-FPM process manager configurable - #133

Merged
peterjaap merged 1 commit into
qoliber:mainfrom
Aquive:feat/configurable-fpm-process-manager
Aug 7, 2026
Merged

peterjaap merged 1 commit into
qoliber:mainfrom
Aquive:feat/configurable-fpm-process-manager

Conversation

@Aquive

@Aquive Aquive commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Problem

Pool configs hardcode pm = dynamic with pm.max_children = 50, sized as if each pool had the machine to itself. With several projects started, the defaults oversubscribe the host — on my 10-core setup, 8 pools meant 400 potential workers, and one Magento page load in developer mode spiked a pool to 46 active workers and the load average to 78.

There is no way to tune it: the values are literals in pool.go / isolated.go, and a hand-edited pool file is overwritten on the next magebox start.

Solution

A pm block in .magebox.yaml / .magebox.local.yaml, plus a default_pm baseline in ~/.magebox/config.yaml:

pm:
  mode: ondemand           # static | dynamic | ondemand
  max_children: 12
  process_idle_timeout: 30s

Precedence is project > global > built-in, merged key by key. ondemand is the useful addition for multi-project machines: dormant projects start no workers at all.

Keys: mode, max_children, max_requests (all modes), start_servers, min_spare_servers, max_spare_servers (dynamic), process_idle_timeout (ondemand). Only the directives valid for the selected mode are rendered.

Validation

Values are checked before the pool file is written, mirroring PHP-FPM's own startup constraints — one malformed pool stops the FPM master, taking down every project on that PHP version. Lowering only max_children scales the untouched spare-server defaults down to fit rather than erroring; explicitly-set values are never rewritten.

Compatibility

Defaults unchanged — without a pm block, pool files render byte-identical. The new argument on Generate/GenerateWithResult/Enable is nullable. Isolated masters persist resolved settings in the registry; older entries fall back to defaults.

Also corrects vitepress/services/php-fpm.md, which documented 5/2/10/500 while the code generates 8/4/12/1000. CHANGELOG.md untouched, as it appears to be maintained in release commits.

Testing

New tests for precedence, merging, the scaling rule, each validation constraint, and pool rendering per mode (including that nil still yields the historical defaults). go test ./..., go vet ./... and golangci-lint run ./... clean.

@peterjaap

Copy link
Copy Markdown
Collaborator

@Aquive looks like Github Actions had an internal error. Could you re--trigger the tests?

Pool configs hardcoded `pm = dynamic` with `pm.max_children = 50`, sized
as if each pool had the machine to itself. On a host running several
projects those defaults collectively oversubscribe it: PHP-FPM starts
workers well past the core count and each active Magento worker can hold
hundreds of megabytes, so a single page load can push the machine into
swap. There was no way to tune this — the values were literals in
pool.go and isolated.go, and a hand-edited pool file is overwritten on
the next `magebox start`.

Add a `pm` block to `.magebox.yaml` / `.magebox.local.yaml` and a
`default_pm` baseline to `~/.magebox/config.yaml`:

    pm:
      mode: ondemand           # static | dynamic | ondemand
      max_children: 12
      process_idle_timeout: 30s

Precedence is project > global > built-in, merged key by key so a local
override can tune a single value. `ondemand` is the notable addition for
multi-project machines: dormant projects start no workers at all.

Only the directives valid for the selected mode are written — `ondemand`
emits `pm.process_idle_timeout` instead of the spare-server keys, and
`static` emits neither.

Values are validated before the pool file is written, mirroring the
constraints PHP-FPM enforces at startup. This matters because a single
malformed pool prevents the FPM master from starting, taking down every
project on that PHP version. Lowering only `max_children` scales the
untouched spare-server defaults down to fit rather than erroring, so the
common case needs one key instead of four.

Defaults are unchanged, so existing installs render byte-identical pool
files. Isolated masters store their resolved settings in the registry so
StartAllIsolated regenerates configs identically without re-reading
project config; entries written by older versions fall back to the
built-in defaults.

Also corrects the pm values in the PHP-FPM service docs, which still
showed 5/2/10/500 rather than the 8/4/12/1000 the code has been
generating.
@Aquive
Aquive force-pushed the feat/configurable-fpm-process-manager branch from 5f0fffe to a3bcf9b Compare August 7, 2026 10:09
@Aquive

Aquive commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@peterjaap done. I couldn't do it by web because of permissions. I did a push to retrigger it.

The current failing job is a permission issue it seems? (Claude: The Comment PR with artifact links job fails on fork PRs because GitHub restricts the workflow's GITHUB_TOKEN to read-only for pull requests from forks).

@peterjaap

Copy link
Copy Markdown
Collaborator

@Aquive yeah that one fails sometimes, it's weird.

Looks like everything's green, merging it! Thanks!

@peterjaap
peterjaap merged commit 98fd0cf into qoliber:main Aug 7, 2026
9 of 10 checks passed
peterjaap pushed a commit that referenced this pull request Aug 7, 2026
The comment-artifacts job requests pull-requests: write, but GitHub caps
GITHUB_TOKEN to read-only for pull_request runs originating from a fork.
Posting the comment therefore fails with 403 'Resource not accessible by
integration', marking the whole run as failed even when every build, test
and lint job passed.

This has broken every fork PR since 1fe4817 added the job (#128, #133, and
external contributions such as #123). PRs from branches in this repository
are unaffected and keep their artifact comment.

Gate the job on the PR originating from this repository instead of merely
being a pull_request. On push events github.event.pull_request is null, so
the job is still skipped there, matching the previous guard.
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.

2 participants