Work-Stealing: GMP's Dynamic Load Balancing Strategy
The GMP model employs a 'work-stealing' mechanism where an idle P (and its bound M) will attempt to steal half of the runnable goroutines from another busy P's local queue. This dynamic load balancing ensures that CPU cores remain highly utilized, preventing starvation and maximizing throughput without central coordination.
The top 3
- Work-Stealing: Pioneering Minds & Early Implementations: The work-stealing scheduling concept originated in the 1980s with research into parallel functional programming by Burton and Sleep, and was notably implemented in Halstead's Multilisp, laying the groundwork for modern concurrent systems. [4, 11, 19]
- Go's GMP: The 3-Step Goroutine Stealing Order: In Go's GMP model, when a Processor (P) runs out of tasks, it first checks its local run queue, then the global run queue (periodically, e.g., 1/61 of the time to ensure fairness), and if both are empty, it attempts to steal half of the goroutines from another random P's local queue. [5, 6, 12, 14, 16]
- Work-Stealing's Key Edge: Hiding Load Balancing Costs: Work-stealing, a pull-based dynamic load-balancing strategy, significantly reduces overhead by allowing idle processors to actively seek and 'steal' tasks. This contrasts with push-based methods where busy processors incur the cost of distributing work, often leading to hidden context-switching overhead on already loaded cores. [10, 18]
Sources
Open the full topic