liveBook · Manning

Work stealing

As explained in 100 Go Mistakes and How to Avoid Them

Work stealing is a scheduling technique in which an underutilized processor obtains runnable tasks from another processor's queue.

An idle processor should not simply wait while runnable goroutines remain elsewhere. Work stealing lets the Go scheduler look into other processors’ local queues and take goroutines to execute. section 8.2.1

When one processor is idle

Suppose a four-core application has runnable goroutines pending in the global queue and local queues, while one processor has no goroutine to execute. After checking its own local queue, the scheduler can steal goroutines from another local queue instead of leaving that processor underused. section 8.2.1

Work stealing is one part of scheduling, not the same as preemption. Since Go 1.14, a goroutine running for about 10 milliseconds can be marked preemptible, allowing a long-running job to share CPU time. section 8.2.1

How 100 Go Mistakes and How to Avoid Them covers it

How deep it goes
Explains queue-search pseudocode and scheduling context, but stops short of runtime implementation details.
Examples
Uses a four-core scheduling state and runtime.schedule pseudocode to illustrate queue checks and stealing.
What it assumes
Assumes familiarity with processors, goroutines, runnable queues, and blocking operations.
What you can do after
Evaluate/understand how Go redistributes runnable goroutines and distinguishes stealing from preemptive context switching.
How it connects
Connects work stealing with goroutines, local queues, the global queue, Go scheduling, and preemption.

Also explained in

Compare how 5 books explain work stealing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 Go Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.