Go runtime એમાં scheduler શામેલ છે જે ઘણા goroutines ને OS threads ની નાની સંખ્યા પર ગુણાકાર કરે છે. આ 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.
