Il runtime di Go include uno scheduler che esegue il multiplexing di molte goroutine su un numero ridotto di thread del sistema operativo. Questo scheduling M:N (M goroutine su N thread del sistema operativo) è ciò che rende le goroutine così economiche e la concorrenza di Go così scalabile. Comprenderlo spiega le prestazioni delle goroutine.
Perché è importante
G (Goroutine) — your concurrent task (lightweight, ~2KB stack to start)
M (Machine) — an OS thread (the actual thread the OS schedules)
P (Processor) — a logical processor / scheduling context; holds a queue of runnable Gs
(the number of P's = GOMAXPROCS, default = number of CPU cores)
The scheduler runs G's on M's, coordinated through P's:
Each P has a local run queue of goroutines; an M must hold a P to run G's.
