Skip to content

Commit 70fb491

Browse files
committed
Add jitter to worker MAX_REQUESTS to prevent thundering herd restarts.
All workers starting with the same limit restart simultaneously, leaving zero workers available during re-bootstrap of 40+ plugins.
1 parent a026aee commit 70fb491

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

webroot/worker.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
$server = new Server($app);
3131

3232
// Max requests before worker restarts (prevents memory leaks)
33+
// Add jitter to prevent all workers restarting simultaneously (thundering herd)
3334
$maxRequests = (int)($_SERVER['MAX_REQUESTS'] ?? 500);
35+
$maxRequests = random_int((int)($maxRequests * 0.8), (int)($maxRequests * 1.2));
3436

3537
// Handle requests in a loop
3638
for ($requestCount = 0; $requestCount < $maxRequests; $requestCount++) {

0 commit comments

Comments
 (0)