nextflow-io / nextflow-io/nextflow
Add Jitter to Task Polling Mechanism
Nobody has claimed this yet.
- Dominant language
- Groovy
- Stars
- 3.5k
- Forks
- 811
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 61
Description
New feature
This proposal is to enhance Nextflow's task polling mechanism by introducing a jitter, which will improve the robustness and efficiency of workflows, especially when interacting with external services.
Use case
The main use case is to prevent the "thundering herd" problem when Nextflow tasks poll external services (e.g., cloud provider APIs like GCP, AWS, Azure, or other web services) for status updates. In scenarios where numerous tasks initiate polling at synchronized, fixed intervals, this can lead to sudden, high-volume bursts of requests. Such bursts can overwhelm external APIs, resulting in rate limiting, increased latency, or temporary service unavailability. Adding jitter will distribute these requests more evenly over time, making Nextflow a more resilient and "API-friendly" client.
Suggested implementation
The core polling logic resides in TaskPollingMonitor.groovy and ParallelPollingMonitor.groovy.
- Identify Polling Loop: The
pollLoop()method inTaskPollingMonitor.groovy(around line 483) is the primary location where the polling interval is enforced via theawait(time)call. - Introduce Jitter Calculation:
- Modify the
await(long time)method (around line 578) or thepollLoop()to introduce a random delay (jitter) to the fixedpollIntervalMillis. - The jitter should be calculated such that there's an inverse relationship between the base polling interval and the jitter factor. For example:
- For a shorter
pollIntervalMillis, a larger percentage of that interval could be used for random jitter. - For a longer
pollIntervalMillis, a smaller percentage of that interval would be used for jitter.
- For a shorter
- A possible formula could be
jitter = random_factor * (max_jitter_percentage / pollIntervalMillis_normalized). - The
random_factorwould be a random number between 0 and 1. - The
max_jitter_percentagewould be a configurable value (e.g., 25% of thepollIntervalMillis). pollIntervalMillis_normalizedcould be thepollIntervalMillisdivided by a base unit (e.g., 1000ms for 1 second) to ensure the inverse relationship scales appropriately.- The final delay would be
pollIntervalMillis + jitter.
- Modify the
- Configuration: Consider adding a new configuration parameter (e.g.,
executor.<name>.pollJitterFactor) toExecutorConfigto allow users to control the maximum jitter percentage, or to enable/disable the jitter. - Impact: This change would be inherited by all executors that use
TaskPollingMonitorandParallelPollingMonitor, including cloud-specific plugins likenf-google.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read TaskPollingMonitor.groovy, especially pollLoop() and await(long time), then compare the related logic in ParallelPollingMonitor.groovy and review ExecutorConfig for configuration patterns. Define the jitter behavior and configuration scope before changing the shared polling mechanism; done means polling delays are desynchronized and the setting applies to the affected executors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend, cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100