Skip to content

Commit

Permalink
ensure idle workers are fed first
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed Nov 21, 2023
1 parent 69fa652 commit 4fc35d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/state/trie_prefetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func (to *trieOrchestrator) stopAcceptingTasks() {
to.tasksAllowed = false

// We don't clear [to.pendingTasks] here because
// it will be faster to prefetch them eventhough we
// it will be faster to prefetch them even though we
// are still waiting.
}

Expand Down
13 changes: 11 additions & 2 deletions utils/bounded_workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,18 @@ func (b *BoundedWorkers) startWorker(f func()) {
func (b *BoundedWorkers) Execute(f func()) {
b.outstandingWork.Add(1)

// Ensure we feed idle workers first
select {
case b.work <- f: // Feed hungry workers first.
case b.workerSpawner <- struct{}{}: // Allocate a new worker to execute immediately next.
case b.work <- f:
return
default:
}

// Fallback to waiting for an idle worker or allocating
// a new worker (if we aren't yet at max concurrency)
select {
case b.work <- f:
case b.workerSpawner <- struct{}{}:
b.startWorker(f)
}
}
Expand Down

0 comments on commit 4fc35d9

Please sign in to comment.