Dedicated Run Queues & Memory Isolation
The BEAM creates a dedicated scheduler and run queue for each CPU core, eliminating the performance bottleneck of a single shared run queue (an issue in older BEAM versions prior to OTP R13B). Coupled with Erlang processes having independent memory spaces (no shared memory), this design avoids costly locking mechanisms and contention during context switches, enabling true parallelism and efficient load balancing across cores.
The top 3
- BEAM's Dedicated Run Queues: Eliminating Global Lock Contention: The BEAM VM employs dedicated run queues, assigning one per scheduler thread (typically one per CPU core), which significantly reduces global lock contention. This architecture, implemented in OTP R13B, allows each scheduler to pull processes from its own queue without needing to synchronize access with other schedulers, streamlining execution and improving parallelism.
- Per-Process Memory Isolation: Fault Tolerance & Simplified GC: Each Erlang process within BEAM has its own isolated stack and heap, preventing direct memory sharing and enforcing 'true isolation.' This design ensures that a crash in one process does not affect others, contributing to Erlang's renowned fault tolerance. Additionally, garbage collection is performed per-process, utilizing a generational semi-space copying collector, which simplifies memory management and avoids global pauses.
- BEAM's 20ns Context Switch: Bypassing OS Overhead: BEAM achieves ultra-fast context switching (reportedly as low as 20 nanoseconds) by managing processes entirely within its VM, avoiding costly operating system kernel calls. Unlike OS-level context switches that involve saving/restoring extensive CPU state, flushing Translation Lookaside Buffers (TLBs), and switching virtual memory spaces, BEAM's lightweight processes (starting around 309 words of memory) allow for rapid state swaps, primarily involving register and pointer updates within the VM's isolated process heaps.
Sources
Open the full topic