Understanding the Go Runtime: The Network Poller
a day ago
- #Network Poller
- #Go Runtime
- #Concurrency
- Go's network poller (netpoller) enables blocking-style API with non-blocking scalability, using platform-specific mechanisms like epoll, kqueue, and IOCP.
- Goroutines park on I/O operations without blocking OS threads, with the runtime managing wake-ups via pollDesc structures that track waiting goroutines.
- A three-step parking protocol (pdNil, pdWait, pointer to g) prevents lost wake-ups by handling races between goroutine sleep and kernel notifications.
- Deadlines are implemented using runtime timers rather than kernel timers, with generation counters to avoid stale notifications from recycled pollDesc instances.
- The scheduler calls netpoll when out of work, and sysmon ensures network I/O isn't stalled by polling every 10ms as a safety net.