BEAM's N:M Scheduler: User-Space Threading
The BEAM virtual machine employs an N:M scheduling model, mapping many lightweight Erlang processes (N) onto a smaller, fixed number of OS threads (M), typically one per CPU core. This allows its user-space scheduler to manage concurrency with minimal kernel intervention.
The top 3
- BEAM's 20ns Context Switch vs. OS Threads' Microseconds: User-space context switching in BEAM occurs in roughly 200 nanoseconds, bypassing costly kernel traps, full register set saves, page table swaps, and TLB flushes, making it orders of magnitude faster than typical OS thread switches which can take 1-3 microseconds.
- Millions of Lightweight Processes on BEAM's N:M Scheduler: BEAM's N:M scheduler allows the creation of millions of concurrent processes due to their extremely lightweight nature, typically starting with only a few hundred bytes of memory, contrasting sharply with OS threads that often require 1MB or more.
- Fairness via Reductions: BEAM's Preemptive Scheduling Metric: Instead of traditional time slices, BEAM's N:M scheduler uses a 'reductions' count (function call increments) to preempt processes, ensuring fair CPU allocation and preventing any single process from monopolizing resources, typically preempting after 2000 reductions.
Sources
Open the full topic