Repository navigation
Add opt-in spread for scheduled function enqueues - #13121
Merged
Merged
Conversation
Cron schedules cluster on shared slots (everyone runs `0 * * * *`), so the scheduler enqueued every same-slot execution in the same second — a thundering herd of simultaneous invocations and runtime cold starts at the top of the hour. When _APP_FUNCTIONS_SCHEDULE_SPREAD is set to N seconds, each function gets a deterministic offset (abs(crc32(functionId)) % N) added to its enqueue delay. Functions keep a stable slot so run intervals stay exact, and enqueue-delay telemetry measures against the intended (spread) time. Default is 0: behavior is unchanged. Co-Authored-By: Claude Fable 5 <[email protected]>
Contributor
Greptile SummaryAdds an opt-in environment setting that deterministically distributes scheduled function enqueues across a configured time window.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Reviews (2): Last reviewed commit: "Merge branch 'main' into feat/schedule-s..." | Re-trigger Greptile |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
ChiragAgg5k
approved these changes
Aug 6, 2026
5 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.
What does this PR do?
Adds an opt-in
_APP_FUNCTIONS_SCHEDULE_SPREADenv var that spreads scheduled function enqueues sharing the same cron slot across a window, instead of enqueuing them all in the same second.Cron schedules cluster on shared slots — a large share of all scheduled functions run
0 * * * *or similar.ScheduleFunctions::enqueueResources()groups schedules by identical delay and enqueues each bucket in one tight loop, so every same-slot execution hits thev1-functionsqueue at exactly:00:00. At scale this is a thundering herd: a burst of simultaneous invocations and runtime cold starts at the top of every hour.With
_APP_FUNCTIONS_SCHEDULE_SPREAD=N, each function gets a deterministic offset —abs(crc32(functionId)) % Nseconds — added to its enqueue delay::00:37, so run intervals stay exact.0= disabled: behavior is byte-for-byte unchanged unless the env var is set.Also registers the variable in
app/config/variables.phpand forwards it to theappwrite-task-scheduler-functionsservice indocker-compose.yml.Test plan
spreadOffset(): determinism, bounds ([0, window)), disabled windows (<= 1→0), and dispersion across distinct function IDs. Verified red with the offset neutered to a constant, green with the real implementation.🤖 Generated with Claude Code