Why Erlang Avoids OS Time-Slicing for Preemption

Unlike traditional OS time-slicing, Erlang's reduction-based preemption prevents CPU monopolization by long-running processes or infinite loops, ensuring responsiveness crucial for soft real-time systems.

The top 3

  1. BEAM's Ultra-Fast Context Switching Advantage: Erlang's BEAM VM handles context switching internally, avoiding costly OS kernel calls and full CPU state saves. This results in switches as fast as 20 nanoseconds, compared to 500-1000 nanoseconds for typical OS threads.
  2. Erlang's Reduction-Based Scheduling Guarantees Fairness: Instead of time-slicing, Erlang's scheduler uses 'reductions' (units of work like function calls) to preempt processes. Each process gets a fixed number of reductions (e.g., 2000) before being swapped out, preventing any single process from monopolizing the CPU and ensuring fair execution and predictable latency.
  3. Optimized for Erlang's Massive Concurrency & Fault Tolerance: Erlang's custom scheduler is purpose-built for its lightweight process model (kilobytes per process) and 'let it crash' philosophy. It efficiently manages millions of isolated processes, enabling automatic load balancing through work stealing and robust fault tolerance that generic OS schedulers cannot match.

Sources

Open the full topic