Go runtime में एक scheduler शामिल है जो कई goroutines को OS threads की एक छोटी संख्या पर multiplexes करता है। यह M:N scheduling (M goroutines N OS threads पर) वह है जो goroutines को इतना सस्ता बनाता है और Go की concurrency को इतनी scalable बनाता है। इसे समझना goroutine performance को समझाता है।
The G-M-P model
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.
