这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@vvzvlad
Copy link

@vvzvlad vvzvlad commented Oct 8, 2025

description: ScheduleNextCheck now adds random jitter of 0–10 minutes to the calculated interval and re-limits the value to the upper limits of the configuration. This reduces the likelihood of massive simultaneous requests to a single host after failed updates and helps bypass frequency limits.

testing: updated check_target_interval to allow for an upper limit of +10m jitter; local linters on changed files without errors.

breaking changes: none

@gabrielecabrini
Copy link

I think that this should be good, maybe add a variable for the max jitter value

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds randomized jitter to the scheduling of feed checks to prevent thundering herd problems when multiple feeds are checked simultaneously. The implementation adds 0-10 minutes of random delay to the calculated check interval while ensuring the final interval still respects the configured maximum limits.

  • Added random jitter (0-10 minutes) to feed check scheduling intervals
  • Updated test helper to account for the additional jitter when validating check times
  • Applied interval clamping after jitter addition to maintain configuration limits

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/model/feed.go Implements jitter logic in ScheduleNextCheck method with random delay and re-clamping
internal/model/feed_test.go Updates test helper to allow for jitter tolerance in interval validation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 150 to 160
if jitterMax > 0 {
jitter := time.Duration(rand.Int63n(int64(jitterMax + 1)))
interval += jitter

// Re-apply max clamping after jitter to avoid exceeding configured caps.
switch config.Opts.PollingScheduler() {
case SchedulerRoundRobin:
interval = min(interval, config.Opts.SchedulerRoundRobinMaxInterval())
case SchedulerEntryFrequency:
interval = min(interval, config.Opts.SchedulerEntryFrequencyMaxInterval())
}
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition jitterMax > 0 is unnecessary since jitterMax is a constant value of 10 minutes. This check can be removed to simplify the code.

Suggested change
if jitterMax > 0 {
jitter := time.Duration(rand.Int63n(int64(jitterMax + 1)))
interval += jitter
// Re-apply max clamping after jitter to avoid exceeding configured caps.
switch config.Opts.PollingScheduler() {
case SchedulerRoundRobin:
interval = min(interval, config.Opts.SchedulerRoundRobinMaxInterval())
case SchedulerEntryFrequency:
interval = min(interval, config.Opts.SchedulerEntryFrequencyMaxInterval())
}
jitter := time.Duration(rand.Int63n(int64(jitterMax + 1)))
interval += jitter
// Re-apply max clamping after jitter to avoid exceeding configured caps.
switch config.Opts.PollingScheduler() {
case SchedulerRoundRobin:
interval = min(interval, config.Opts.SchedulerRoundRobinMaxInterval())
case SchedulerEntryFrequency:
interval = min(interval, config.Opts.SchedulerEntryFrequencyMaxInterval())

Copilot uses AI. Check for mistakes.
Copy link
Member

@fguillot fguillot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside the comment opened by Copilot, is it possible to avoid the duplication of code regarding the switch/case?

feat: add config variable for polling jitter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants