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

Immediately fetch another batch when a full set of job is returned #663

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (p *producer) fetchAndRunLoop(fetchCtx, workCtx context.Context, fetchLimit
if p.paused {
continue
}
p.innerFetchLoop(workCtx, fetchResultCh)
p.innerFetchLoop(workCtx, fetchResultCh, fetchLimiter)
// Ensure we can't start another fetch when fetchCtx is done, even if
// the fetchLimiter is also ready to fire:
select {
Expand All @@ -461,7 +461,7 @@ func (p *producer) fetchAndRunLoop(fetchCtx, workCtx context.Context, fetchLimit
}
}

func (p *producer) innerFetchLoop(workCtx context.Context, fetchResultCh chan producerFetchResult) {
func (p *producer) innerFetchLoop(workCtx context.Context, fetchResultCh chan producerFetchResult, fetchLimiter *chanutil.DebouncedChan) {
limit := p.maxJobsToFetch()
go p.dispatchWork(workCtx, limit, fetchResultCh)

Expand All @@ -472,6 +472,13 @@ func (p *producer) innerFetchLoop(workCtx context.Context, fetchResultCh chan pr
p.Logger.ErrorContext(workCtx, p.Name+": Error fetching jobs", slog.String("err", result.err.Error()))
} else if len(result.jobs) > 0 {
p.startNewExecutors(workCtx, result.jobs)

// Fetch returned the maximum number of jobs that were requested
// which implies there may be more in the queue so trigger another
// fetch right after this one.
if len(result.jobs) == limit {
fetchLimiter.Call()
}
}
return
case result := <-p.jobResultCh:
Expand Down
Loading