A Go runtime egy scheduler-t tartalmaz, amely sok goroutine-t sokszoros-e el egy kis számú OS szál felé. Ez az M:N scheduling (M goroutine N OS szálon) az, ami a goroutine-okat olyan olcsóvá és a Go konkurenciáját olyan skálázhatóvá teszi. Ennek megértése magyarázza a goroutine teljesítményt.
A G-M-P modell
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.
