- Notifications
You must be signed in to change notification settings - Fork11.7k
Laravel Octane worker count#52133
-
Hi, Laravel Octane states that it'll create aworker for each CPU core. I'm wondering here, how many requests then can an actual CPU core handle or is it better to actually just set the number of workers significantly higher than what Octane thinks it should start? |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment 2 replies
-
Every worker can only handle 1 request at a time. So if the worker count is equal to the CPU count it could happen that there are not enough workers to fully utilize your CPU cores if many workers are simultaneously busy fetching from cache/database/filesystem (which will make them block). So a good default setting would be to use around 2x times as many workers as you have CPU cores to ensure that the CPUs are being used to a fuller extent.Frankenphp will actually create 2x the amount of workers, which is probably a better default thanSwoole which will does 1x CPU cores. TheSwoole default probably comes from it most often being used in its async mode, where 1x the number of CPU cores is enough to fully utilize all CPU cores. Laravel Octane does not run asynchronous though so it benefits from a higher amount of workers. Why not use many more workers then? The tradeoff for having more workers is that you also consume more memory. The bottleneck will more often be your CPU though. |
BetaWas this translation helpful?Give feedback.
All reactions
-
is there a way to see the number of running workers? |
BetaWas this translation helpful?Give feedback.
All reactions
-
FrankenPHP exposes Prometheusmetrics for that. If you just want to debug, you can also ping the admin api directly (usually running on port 2019. # ping metrics for debuggingcurl http://localhost:2019/metrics# see all thread states for debuggingcurl http://localhost:2019/frankenphp/threads In the newer FrankenPHP versions you can also let threads spawn automatically, so I'd recommend something like 5-10x CPU cores viamax_threads. |
BetaWas this translation helpful?Give feedback.