Add Queue.workerLifetimeJitter to stagger worker shutdowns#476
Open
dereuromark wants to merge 2 commits intomasterfrom
Open
Add Queue.workerLifetimeJitter to stagger worker shutdowns#476dereuromark wants to merge 2 commits intomasterfrom
dereuromark wants to merge 2 commits intomasterfrom
Conversation
Each worker picks a random offset in [0, workerLifetimeJitter] at startup and adds it to its effective lifetime. Prevents thundering-herd restarts when a fleet of workers (e.g. ECS/Kubernetes tasks) is spawned at the same instant and would otherwise all exit on the same tick. Defaults to 0 (no jitter), preserving existing behavior. Idea and original implementation (against a legacy CakePHP 2.x fork) by Rommel Penaflor (@xrompdev) in #475; ported to the modern processor.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #476 +/- ##
=========================================
Coverage 77.22% 77.22%
- Complexity 949 954 +5
=========================================
Files 45 45
Lines 3196 3219 +23
=========================================
+ Hits 2468 2486 +18
- Misses 728 733 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional
Queue.workerLifetimeJitterconfig (seconds). Each worker picks a random offset in[0, workerLifetimeJitter]at startup and adds it to its effectiveworkerLifetime/--max-runtime. When a fleet of workers is spawned at the same instant (ECS tasks, Kubernetes deployments, systemd unit with many instances), this prevents every worker from terminating on the same tick and producing a thundering-herd of simultaneous restarts.Defaults to
0, so behavior is unchanged unless the option is set.Credit
Idea and original implementation by Rommel Penaflor (@xrompdev) in #475, where it was proposed against a legacy CakePHP 2.x Symphosize fork and therefore could not be merged directly. This PR is a fresh port to the modern
Queue\Queue\Processor, keeping the operational intent intact.Implementation notes
$startTime = time()inProcessor::run()), not re-rolled each loop iteration, so the exit time is stable per worker.Processor::computeLifetimeJitterOffset()so the bounds/default behavior is unit-testable without spinning up the full run loop.$maxRuntime > 0— unlimited workers stay unlimited.<= 0jitter values are ignored (returns 0), so a misconfigured negative value is a no-op rather than an error.Applying worker lifetime jitter: +Ns secondsso operators can see the stagger in action.Docs
Added a dedicated bullet in
docs/sections/configuration.mddirectly after theworkerLifetimesection, explaining the ECS/K8s use case.