Go ਰਨਟਾਈਮ ਵਿੱਚ ਇੱਕ scheduler ਹੈ ਜੋ ਬਹੁਤ ਸਾਰੇ goroutines ਨੂੰ OS threads ਦੀ ਇੱਕ ਛੋਟੀ ਸੰਖਿਆ ਤੇ ਮਲਟੀਪਲੈਕਸ ਕਰਦਾ ਹੈ। ਇਹ M:N scheduling (M goroutines ਨੂੰ N OS threads ਤੇ) ਹੀ ਹੈ ਜੋ goroutines ਨੂੰ ਇੰਨਾ ਸਸਤਾ ਅਤੇ Go ਦੇ concurrency ਨੂੰ ਇੰਨਾ scalable ਬਣਾਉਂਦਾ ਹੈ। ਇਸ ਨੂੰ ਸਮਝਣਾ goroutine performance ਨੂੰ ਸਮਝਾਉਂਦਾ ਹੈ।
G-M-P ਮਾਡਲ
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.
