Node-RED runtime latency during high-volume Debug node output
0 reputation · 18 Jan 2021, 17:46 UTC
0 reputation · 18 Jan 2021, 17:46 UTC
Node-RED operates on a single-threaded Node.js event loop. When flows are configured to process high-frequency message bursts, the runtime may experience significant latency or reduced editor responsiveness.
A specific concern arises when the Debug node is used to monitor large payloads or rapid message streams. Because these outputs must be transmitted to the sidebar or system console, the overhead of processing these messages can compete with the execution of the primary flow logic.
There is uncertainty regarding the exact threshold where Debug node activity begins to block the event loop, particularly when combined with CPU-intensive Function nodes.
34775 reputation · 18 Jan 2021, 18:04 UTC
The Debug node adds latency primarily by sending each message over a socket.io connection to the editor UI. The UI must JSON‑stringify the msg object and update the debug sidebar, which runs on Node‑RED’s single‑threaded event loop. When the message rate is high, this work blocks the loop and delays subsequent flow execution.
Each Debug node emission triggers a socket.io event, serialization, and DOM update. The CPU time spent on these steps adds directly to event‑loop latency; latency grows roughly linearly with messages per second until the loop is saturated.
msg.payload (complete:false) reduces the size of the serialized object.node-red --settings ./settings.js with httpNodeRoot: false or simply omit the editor).msg.payload only.node-red-contrib-file) or a function node that uses console.log; this bypasses socket.io entirely.GET /events) or a simple setInterval that logs Date.now() - lastTick to correlate spikes with debug bursts.Are you observing the latency with the editor UI attached (sidebar open) or when Node‑RED is running headless? Knowing this determines whether UI‑related socket.io work is the primary cause and whether headless mode alone would resolve the issue.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 19 Jan 2021, 02:37 UTC
While the admin API’s /events endpoint exposes a coarse event‑loop delay, perf_hooks.monitorEventLoopDelay() gives a fine‑grained histogram you can embed in a function node:
const delay = require('perf_hooks').monitorEventLoopDelay();
delay.enable();
// … flow runs …
console.log('avg delay', delay.mean / 1e6, 'ms');
Run the flow with the debug node toggled on/off and compare the mean delay. This isolates the debug overhead from other CPU‑heavy nodes.
Start Node‑RED with node --trace-gc. In the log you’ll see gc start and gc end entries. High debug traffic often triggers frequent scavenge GC; sustained allocation can push objects into the old generation, causing a major GC pause that appears as a latency spike.
function node to pre‑serialize only the fields you care about before sending to debug.delay node (e.g., 100 ms) to reduce the number of serializations per second.