BEAM vs. OS Threads: Minimal Footprint Comparison
A BEAM process typically starts with just 2-3 KB of memory, while a traditional OS thread (like a JVM thread) often consumes 1-2 MB, making BEAM processes up to 1000 times more memory efficient.
The top 3
- BEAM Processes: Kilobytes vs. Megabytes Memory Footprint: Erlang/Elixir BEAM processes typically start with a memory footprint of just 0.5 KB to 3 KB, enabling millions of concurrent processes on a single machine, while OS threads often require 1 MB to 8 MB of stack space, limiting practical concurrency to thousands.
- BEAM's Concurrency Advantage: Millions vs. Thousands of Threads: Due to their minimal memory footprint and VM-level management, BEAM processes can scale to millions of concurrent agents on a single server, exemplified by systems like WhatsApp, whereas OS threads are typically limited to thousands due to memory and OS scheduling overhead.
- BEAM's Context Switching: VM-Managed Speed vs. OS Kernel Overhead: BEAM processes achieve significantly faster context switching, handled efficiently within the virtual machine in microseconds, minimizing overhead. In contrast, OS threads rely on the operating system kernel for context switching, which is substantially more resource-intensive, involving saving larger states and potentially flushing memory caches like the TLB.
Sources
Open the full topic