Node-RED Global Context and Node.js Heap Memory Integration
25.5K reputation · 20 Jul 2023, 11:06 UTC
Memory Management in Global Context
Node-RED utilizes the Node.js runtime, where the global context API provides a mechanism for sharing data across different flows. By default, this context is stored in memory, meaning any objects or arrays assigned to the global scope reside directly on the Node.js heap.
While the runtime handles standard garbage collection, there is a known architectural gap regarding the isolation of memory consumption. Specifically, there is no native, declarative method to set a memory quota or limit for a specific flow or individual function node. This creates a risk where a single flow utilizing the memory-based global store can exhaust the entire process heap, leading to Out-of-Memory (OOM) crashes for the entire Node-RED instance.
Given the current implementation of the Context Storage API in recent versions, what are the best practices for preventing a single flow from impacting the global heap? Is there a way to implement per-flow memory constraints without migrating the entire global store to a file-based or database-backed persistence layer?