Skip to content

Commit 960dd20

Browse files
feat: multiple workers with same file (#1856)
* Allow multiple workers with the same file. * Fix formatting of duplicate filename check * Adds docs. * suggestions by @alexandre-daubois. * Update performance.md --------- Co-authored-by: Kévin Dunglas <[email protected]>
1 parent 984f0a0 commit 960dd20

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

caddy/module.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ func (f *FrankenPHPModule) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
264264
if _, ok := fileNames[w.FileName]; ok {
265265
return fmt.Errorf(`workers in a single "php_server" block must not have duplicate filenames: %q`, w.FileName)
266266
}
267-
fileNames[w.FileName] = struct{}{}
267+
268+
if len(w.MatchPath) == 0 {
269+
fileNames[w.FileName] = struct{}{}
270+
}
268271
}
269272

270273
return nil

docs/performance.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,36 @@ In particular:
155155

156156
For more details, read [the dedicated Symfony documentation entry](https://symfony.com/doc/current/performance.html)
157157
(most tips are useful even if you don't use Symfony).
158+
159+
## Splitting The Thread Pool
160+
161+
It is common for applications to interact with slow external services, like an
162+
API that tends to be unreliable under high load or consistently takes 10+ seconds to respond.
163+
In such cases, it can be beneficial to split the thread pool to have dedicated "slow" pools.
164+
This prevents the slow endpoints from consuming all server resources/threads and
165+
limits the concurrency of requests going towards the slow endpoint, similar to a
166+
connection pool.
167+
168+
```caddyfile
169+
{
170+
frankenphp {
171+
max_threads 100 # max 100 threads shared by all workers
172+
}
173+
}
174+
175+
example.com {
176+
php_server {
177+
root /app/public # the root of your application
178+
worker index.php {
179+
match /slow-endpoint/* # all requests with path /slow-endpoint/* are handled by this thread pool
180+
num 10 # minimum 10 threads for requests matching /slow-endpoint/*
181+
}
182+
worker index.php {
183+
match * # all other requests are handled separately
184+
num 20 # minimum 20 threads for other requests, even if the slow endppoints start hanging
185+
}
186+
}
187+
}
188+
```
189+
190+
Generally it's also advisable to handle very slow endpoints asynchronously, by using relevant mechanisms such as message queues.

0 commit comments

Comments
 (0)