Open calvinalkan opened 4 days ago
Num threads is the total number of php threads (this doesn't affect the number of go threads). Worker threads consume php threads (must be less or equal to total threads). Non worker threads handle requests not covered by the worker. For example, an advanced configuration might delegate api requests to a worker, but authentication to a non-worker.
Thanks, makes sense.
So for a project with just one worker and nothing else, you could just set num_threads
= worker.num
I found that the worker.num
still needs to be explicit. Otherwise frankenphp will try to read it from GOMAXPROCS, even if num_threads
is defined.
Related to this, I found your advice on tweaking GOMAXPROCS:
https://github.com/dunglas/frankenphp/discussions/294#discussioncomment-7504697
Would you still recommend this today?
I'd say that it largely depends on your load and what you are doing in PHP. We're often dealing with "ideal" situations when doing load tests and figuring out the bottlenecks. That is probably not the answer you want though. :)
Just remember one worker means you can handle only one request at a time, so if your php script takes a full 10s to return, you won't be able to accept another request until another completes. If your requests are not very CPU-intensive, you can often have far more workers than CPUs (but one or two workers per CPU is usually more efficient). These threads are analogous to fpm-workers, and the tuning of the numbers is very similar (you don't want vastly more fpm-workers than CPUs, or your max RPS will actually be lower than what it is actually possible to achieve; keeping in mind memory usage as well, because if you overcommit, one bad request can bring the ire of the OOM-Killer).
The main thing is hardware. Go is multi-threaded and is meant to run on servers/desktops with lots of CPUs. If you have too few CPUs, performance will suffer due to context switching.
Thanks!
With "one worker"
I meant "one worker configuration entry"
frankenphp {
{$CADDY_FRANKENPHP_OPTIONS}
worker {
file "{$APP_PUBLIC_PATH}/frankenphp-worker.php"
{$CADDY_FRANKENPHP_WORKER_WATCH_OPTIONS}
{$CADDY_FRANKENPHP_WORKER_NUM_THREADS}
}
}
In, which case, a config with substituted env variables might be:
frankenphp {
num_threads: 49
worker {
file "{$APP_PUBLIC_PATH}/frankenphp-worker.php"
num 48
}
}
What happened?
It's not clear to me what I need to configure if I'm only using the worker mode (in Laravel).
No matter what I do, frankenphp seems to always start with 48 threads (2x my CPU).
htop:
I tried harcoding it to 2 threads, but it's still the same outcome
Maybe this is expected?
I'd be nice to have an explanation in the docs for the difference/relation between
frankenphp.num_threads
andfrankenphp.worker.num
Does one supersede the other? Do they configure different things?
Build Type
Docker (Debian Bookworm)
Worker Mode
Yes
Operating System
GNU/Linux
CPU Architecture
x86_64
PHP configuration
Relevant log output
No response