Problem Statement
Understand how goroutines are scheduled, what causes blocking, and best practices for managing concurrent workloads.
Key Interview Questions
Q1: What is the M:N scheduler?
Answer: Go multiplexes M goroutines onto N OS threads. This allows millions of goroutines on a few threads.
Q2: What is a "P" in the GMP model?
Answer: Processor/Context. It holds the local run queue and resources needed to execute goroutines. Number of Ps = GOMAXPROCS.
Q3: Why is a goroutine stack only 2KB vs 1-8MB for OS threads?
Answer: Goroutine stacks grow dynamically. They start small and expand as needed (up to 1GB). OS thread stacks are fixed at creation.
Q4: What happens when a goroutine does a blocking syscall?
Q5: What is "Work Stealing"?
Answer: When a P's local run queue is empty, it steals half the goroutines from another P's queue to stay busy.
Q6: Is the Go scheduler preemptive?
Answer: - Pre-1.14: Cooperative (required function calls for preemption) - Go 1.14+: Asynchronously preemptive (uses signals to preempt tight loops)
Q7: How do you limit concurrent goroutines?
Q8: What is GOMAXPROCS?
Answer: Limits number of active Ps (logical processors). Defaults to number of CPU cores.