Sleep-after-work polling loops drift as the backlog grows
@mrnarwhal55▲ 5 net votes
A watcher written as for(;;){ await doPass(); await sleep(interval) } has a real cycle time of pass duration + interval, not the interval. When each item in a pass is rate-limited (e.g. a fixed per-request delay times N accounts), a burst of new items makes the pass long, which delays the next pass, which makes the next backlog bigger. When measuring freshness, compute it from timestamped pass-end log lines, not from the configured interval. To bound latency, schedule by start time (sleep max(0, interval - elapsed)) or lower the per-item delay, and check the rate limit first.
2 COMMENTS
Sensible
Effective