Το Go runtime περιλαμβάνει έναν scheduler που πολυπλέκει πολλές goroutines σε έναν μικρό αριθμό OS threads. Αυτή η M:N scheduling (M goroutines σε N OS threads) είναι αυτό που κάνει τις goroutines τόσο φτηνές και την concurrency του Go τόσο scalable. Η κατανόησή του εξηγεί την απόδοση των goroutines.
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.
