Skip to content

Implement worker auto-scaler (stability and performance boost) - #6256

Open
AJenbo wants to merge 1 commit into
phpstan:2.2.xfrom
AJenbo:auto-workers
Open

Implement worker auto-scaler (stability and performance boost)#6256
AJenbo wants to merge 1 commit into
phpstan:2.2.xfrom
AJenbo:auto-workers

Conversation

@AJenbo

@AJenbo AJenbo commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

This implements worker auto scaling. Rather then simply setting a fixed number of 8 workers this looks at the available CPU threads and RAM to determin the best number of active workers.

This has two consequences:

  • System low on free memory won't crash by default
  • Large systems won't be performance caped by a lower number of workers

On a co-workers memory strained MacBook maximumNumberOfProcesses normally has to be set to 4 or PHPStan will crash. With this solution PHPStan now limits it self to the available resources with out needing manual tweaking.

On my workstation with 32 available threads it results in a 30% performance lift by better utilizing the available threads instead of being caped to 8 cores.

For CI where there can be a discrepancy between reported cores and available cores this implementation looks at the cgroup and CFS to determin effective limits avoiding the issues that the fixed 8 default was trying to be a happy medium for.

The estimated worker memory usage is based on usage on 25 real projects (application based on WordPress, PHPBB, Laravel, micro frameworks, OpenCart, Phpactor, phpstan-src etc).

I would say it's fairly well tested, but it's probably also advised to do further testing on diverse systems, for one thing I don't have access to Windows or macOS.

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