The Curious Case of Beam CPU Usage (2019)
Published on: 2025-05-19 21:07:40
While benchmarking Go vs Elixir vs Node, we discovered that Elixir (running on the BEAM virtual machine) had much higher CPU usage than Go, and yet its responsiveness remained excellent. Some of our readers suggested that busy waiting may be responsible for this behavior.
Turns out, busy waiting in BEAM is an optimization that ensures maximum responsiveness.
In essence, when waiting for a certain event, the virtual machine first enters a CPU-intensive tight loop, where it continuously checks to see if the event in question has occurred.
The standard way of handling this is to let the operating system kernel manage synchronization in such a way that, while waiting for an event, other threads get the opportunity to run. However, if the event in question happens immediately after entering the waiting state, this coordination with the kernel can be wasteful.
An interesting side effect of the busy wait approach is that CPU utilization reported by the operating system becomes misleading.
... Read full article.