Add support for jitter so that we can ensure evenly distributed tasks don't cause all workers to restart at same time#570
Merged
s3rius merged 4 commits intotaskiq-python:masterfrom May 4, 2026
Conversation
Contributor
Author
|
@s3rius I would be curious as to whether you think this is valuable or not? I hit an issue where in ensuring even distribution, my workers across 3 replicas would end up shutting down around the same time given the extremely high task usage |
s3rius
approved these changes
Apr 20, 2026
… don't cause all workers to restart at same time
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #570 +/- ##
==========================================
+ Coverage 79.37% 79.41% +0.03%
==========================================
Files 69 69
Lines 2473 2477 +4
==========================================
+ Hits 1963 1967 +4
Misses 510 510 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
This PR adds jitter support to the
max_async_tasksparameter to prevent synchronized worker restarts. When multiple workers are configured with the samemax_async_taskslimit and receive evenly distributed tasks, they tend to hit their limits simultaneously, causing cascading restarts that can impact system stability.Changes
max_async_tasks_jitterparameter: Added across the receiver, broker, and CLI interfaces to configure randomized jittermax_async_taskslimit when creating the semaphore--max-async-tasks-jitterflag to worker command for runtime configurationTechnical Details
The implementation distributes worker restart times by randomizing each worker's actual task limit. For example, with
max_async_tasks=100andmax_async_tasks_jitter=10, workers will have limits ranging from 100 to 110. This prevents the thundering herd problem where synchronized restarts cause all workers to compete for the same resources simultaneously, leading to more graceful degradation under load.