Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: jitter on cron jobs #953

Merged
merged 3 commits into from
Aug 19, 2024
Merged

feat: jitter on cron jobs #953

merged 3 commits into from
Aug 19, 2024

Conversation

adityathebe
Copy link
Member

No description provided.

job/job.go Outdated
}
j.entryID = &entryID
} else {
delaydJob := cron.FuncJob(func() {
Copy link
Member

Choose a reason for hiding this comment

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

I think the jitter should be once off at the start, i.e. delay the scheduling of the job by random(min(duration till next runtime, 1h))

@adityathebe adityathebe marked this pull request as ready for review August 19, 2024 12:39
@adityathebe
Copy link
Member Author

@moshloop I'm leaving off delaying the initial scheduling even though we discussed we would add a 100% jitter to it.

The problem is that if we delay the scheduling by running entryID, err := cronRunner.AddJob(schedule, delayedJob) in a goroutine, the AddToScheduler func returns with no error but the job actually hasn't been scheduled. i.e. job.entryID = nil.

If the job needs to be rescheduled (scraper CRD updated) when it's still waiting for first schedule, then it's not possible to unschedule is as we won't have the entryID.

I think let's try with per iteration jitter for now and see how it goes?

job/job.go Outdated Show resolved Hide resolved
job/job.go Show resolved Hide resolved
job/job.go Outdated Show resolved Hide resolved
job/job.go Outdated
delayPercent := rand.Intn(iterationJitterPercent)
jitterDuration := time.Duration((int64(interval) * int64(delayPercent)) / 100)
if jitterDuration > maxJitterDuration {
jitterDuration = maxJitterDuration
Copy link
Member

Choose a reason for hiding this comment

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

I think this will have fixed 15m jitters, so if interval * delayPercent then interval = 15m

@moshloop moshloop merged commit 4c5b640 into main Aug 19, 2024
6 checks passed
@moshloop moshloop deleted the feat/job-jitter branch August 19, 2024 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants