Process memory model
process.memoryUsage() returns:
| Field | Meaning |
|---|---|
rss |
Resident Set Size — total process memory in RAM |
heapTotal |
V8 heap allocated |
heapUsed |
V8 heap in use |
external |
C++ objects bound to JS (Buffers, etc.) |
arrayBuffers |
Memory for ArrayBuffers (Node 16+) |
flowchart TB rss[RSS total process] heap[heapUsed / heapTotal] ext[external + arrayBuffers] native[Native code stacks etc] rss --> heap rss --> ext rss --> native
Healthy vs leaking server
Section titled “Healthy vs leaking server”Healthy: heapUsed sawtooths — spikes on work, dips after major GC.
Leaking: heapUsed and often rss stair-step upward over hours with steady traffic.
Logging snippet
Section titled “Logging snippet”function logMemory(label) { const m = process.memoryUsage(); console.log(label, { rssMB: (m.rss / 1024 / 1024).toFixed(1), heapUsedMB: (m.heapUsed / 1024 / 1024).toFixed(1), externalMB: (m.external / 1024 / 1024).toFixed(1), });}Run every N seconds in staging to build intuition before Grafana.
Broken pattern
Section titled “Broken pattern”Monitoring only CPU — memory creep is invisible until OOM.
Fixed pattern
Section titled “Fixed pattern”Alert on 7-day trend of heapUsed / rss, not single spikes. Pair with deployment markers.