Skip to main content

Posts

Showing posts with the label Erlang

Hot-Debugging the BEAM: Tracing Erlang Processes in Live Production without Downtime

  Your metrics dashboard is screaming. Latency on the payment processing node has spiked to 5000ms. Memory usage is climbing vertically. The logs are paradoxically silent. You know a GenServer is stuck, or a message queue is overflowing, but you don't know   which   one. In most runtimes, your only move is to capture a heap dump and restart the service, severing active connections and losing in-flight state. The BEAM (Erlang VM) is different. It was designed for systems that cannot go down. You can surgically attach a remote shell to the running cluster, identify the rogue process, inspect its internal state, and even trace function calls in real-time—all without stopping the world. Here is how to safely diagnose a zombie process in a high-throughput production environment. The Root Cause: Mailboxes and Reductions To fix a stuck BEAM node, you must understand how it breaks. Mailbox Overflow:  Every process (Actor) has a mailbox. If a GenServer receives  cast ...

Debugging Erlang Mailbox Overflows with OTP 27 Monitors

  The most insidious failure mode in the BEAM virtual machine is the silent mailbox overflow. Unlike a stack overflow or a logic error, a message queue buildup doesn't immediately crash the process. Instead, it slowly consumes memory, degrades garbage collection performance, and eventually triggers the system-wide Out-Of-Memory (OOM) killer, taking down the entire node. Until recently, detecting this required reactive polling loops or expensive introspection tools like  recon  that could exacerbate the load. With the release of OTP 27, we now have a native, event-driven mechanism to handle this at the VM level: the  message_queue_len  monitor. The Root Cause: Asynchronous Coupling and GC Erlang processes communicate asynchronously. When Process A sends a message to Process B, the message is copied to B's heap (or the shared heap for large binaries) and appended to its mailbox linked list. Process B consumes these messages via  receive  or  gen_ser...