Go's Work-Stealing: Solution to Global Queue Bottlenecks
Go's decentralized work-stealing approach, introduced in Go 1.1, solves the contention and scalability issues of older centralized global run queue models. Each P manages a local queue, reducing the need for locks and allowing most scheduling decisions to be cheap and efficient, improving multi-core performance.
The top 3
- Go's Local Queues vs. Global Bottlenecks: Go's scheduler primarily utilizes per-processor local run queues, drastically reducing mutex contention inherent in systems relying solely on a single global queue. Work-stealing is a decentralized mechanism that only engages when a local queue is empty, ensuring most goroutine scheduling operations remain lock-free and efficient.
- How Go's Work-Stealing Balances Load: When a Go logical processor (P) exhausts its local queue of goroutines, it actively attempts to "steal" work. It randomly selects another P and takes approximately half of its runnable goroutines, moving them to its own local queue to maintain high CPU utilization and efficient load distribution.
- Go's Anti-Starvation Scheduling Rules: To prevent goroutines from indefinitely starving in the global run queue, Go's scheduler incorporates a '61-tick rule,' periodically checking the global queue (approximately every 61 scheduling iterations) even when local queues are busy, ensuring a balance between local efficiency and global fairness.
Sources
Open the full topic