Does max_memory_restart trigger based on RSS or Heap usage?
19K reputation · 27 Apr 2022, 21:14 UTC
PM2 provides the max_memory_restart option to automatically reboot a process when it exceeds a specific memory threshold. This is often used as a safeguard against gradual memory leaks in Node.js applications.
In a production environment using PM2 v5.x, there is uncertainty regarding which specific memory metric the process manager monitors to trigger this restart. Node.js differentiates between Resident Set Size (RSS), which represents the total memory allocated for the process, and the V8 Heap usage, which tracks the memory used by the application's objects.
If the threshold is based on RSS, the process may restart due to external buffer allocations or native modules, even if the V8 heap remains stable. Conversely, if it monitors the heap, it might ignore growth in the resident set.
- Which specific memory metric does PM2 track to evaluate the
max_memory_restartlimit? - Does this behavior change when running in cluster mode versus fork mode?