Go runtime, birçok goroutine'i küçük sayıda OS thread'ine multipleks eden bir scheduler içerir. Bu M:N scheduling (M goroutine'in N OS thread'inde çalışması) goroutine'leri bu kadar ucuz ve Go'nun concurrency'sini bu kadar ölçeklenebilir yapan şeydir. Bunu anlamak goroutine performansını açıklar.
G-M-P modeli
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.
