In prod, uptimesebi_checks_overdue rises and falls in triangle waves of about 10 minutes, peaking at 26K per region. The checkers keep up on average; the runs just arrive bunched:
A monitor's next run was at + interval, so monitors created together (import, load test, a new region, reconcile after a Redis loss) stay due in the same second for good.
Late runs were rescheduled to now + interval, gathering them at the dispatch time.
What
Every monitor has a fixed phase within its interval: uint64(id[8:16]) mod intervalMS, stored in the new hash sched:phases.
The first run stays immediate, as before.
Every later run lands on the monitor's next slot after now. A run off its slot, like the first one, skips a slot less than half an interval away, so a monitor never runs twice in quick succession.
Late runs snap to their own slot instead of bunching.
Reconcile adds lost monitors on their slot, not on now, so rebuilding a schedule causes no burst. Only Upsert from the API runs right away.
Remove and the prune script also drop the phase.
Monitors without a phase (written before this release) keep the old rule until the next reconcile, within a minute.
Existing clusters break up on their own within one interval of each monitor after rollout.
Tests
New: TestPhaseSpreadsBurst (600 monitors at once: all first runs in second 0, then at most 30 per second at a mean of 10), TestLateRunSnapsToPhase, TestReconcileAddsOnPhase, TestPhaseFallback, TestNextSlot.
Adapted TestDispatchReschedulesAndKeepsRegionsApart: the next run is on the phase, between half and one and a half intervals later.
go test ./... with DB and Redis, and golangci-lint: green.
Dev stack: 200 monitors at 60 s created at once. After the first burst, dispatch per second stays flat (about 3.4/s, max 9) instead of 200 every minute.
## Why
In prod, `uptimesebi_checks_overdue` rises and falls in triangle waves of about 10 minutes, peaking at 26K per region. The checkers keep up on average; the runs just arrive bunched:
- A monitor's next run was `at + interval`, so monitors created together (import, load test, a new region, reconcile after a Redis loss) stay due in the same second for good.
- Late runs were rescheduled to `now + interval`, gathering them at the dispatch time.
## What
- Every monitor has a fixed **phase** within its interval: `uint64(id[8:16]) mod intervalMS`, stored in the new hash `sched:phases`.
- The **first run stays immediate**, as before.
- Every later run lands on the monitor's next slot after `now`. A run off its slot, like the first one, skips a slot less than half an interval away, so a monitor never runs twice in quick succession.
- Late runs snap to their own slot instead of bunching.
- `Reconcile` adds lost monitors on their slot, not on `now`, so rebuilding a schedule causes no burst. Only `Upsert` from the API runs right away.
- `Remove` and the prune script also drop the phase.
- Monitors without a phase (written before this release) keep the old rule until the next reconcile, within a minute.
Existing clusters break up on their own within one interval of each monitor after rollout.
## Tests
- New: `TestPhaseSpreadsBurst` (600 monitors at once: all first runs in second 0, then at most 30 per second at a mean of 10), `TestLateRunSnapsToPhase`, `TestReconcileAddsOnPhase`, `TestPhaseFallback`, `TestNextSlot`.
- Adapted `TestDispatchReschedulesAndKeepsRegionsApart`: the next run is on the phase, between half and one and a half intervals later.
- `go test ./...` with DB and Redis, and golangci-lint: green.
- Dev stack: 200 monitors at 60 s created at once. After the first burst, dispatch per second stays flat (about 3.4/s, max 9) instead of 200 every minute.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
A monitor's next run was its last due time plus the interval, so monitors
created together, by an import or a test, stayed due in the same second
for good, and late runs all gathered at the dispatch time. In prod, regions
fell behind in waves every interval although the checkers kept up on
average.
Each monitor now has a fixed phase within its interval, from its ID.
After the first run, still right away, it runs on its phase; late runs
snap to their next slot. Reconcile adds lost monitors on their phase, so
rebuilding a schedule causes no burst either. Monitors scheduled before
phases existed keep the old rule until reconciliation adds their phase.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi
merged commit 9d1d6a2544 into main2026-11-29 15:08:04 +00:00
Sebi
deleted branch feat/schedule-phase2026-11-29 15:08:07 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Why
In prod,
uptimesebi_checks_overduerises and falls in triangle waves of about 10 minutes, peaking at 26K per region. The checkers keep up on average; the runs just arrive bunched:at + interval, so monitors created together (import, load test, a new region, reconcile after a Redis loss) stay due in the same second for good.now + interval, gathering them at the dispatch time.What
uint64(id[8:16]) mod intervalMS, stored in the new hashsched:phases.now. A run off its slot, like the first one, skips a slot less than half an interval away, so a monitor never runs twice in quick succession.Reconcileadds lost monitors on their slot, not onnow, so rebuilding a schedule causes no burst. OnlyUpsertfrom the API runs right away.Removeand the prune script also drop the phase.Existing clusters break up on their own within one interval of each monitor after rollout.
Tests
TestPhaseSpreadsBurst(600 monitors at once: all first runs in second 0, then at most 30 per second at a mean of 10),TestLateRunSnapsToPhase,TestReconcileAddsOnPhase,TestPhaseFallback,TestNextSlot.TestDispatchReschedulesAndKeepsRegionsApart: the next run is on the phase, between half and one and a half intervals later.go test ./...with DB and Redis, and golangci-lint: green.🤖 Generated with Claude Code
https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3