Node-RED restarts (out of memory) + solution

I’m running Node-RED on Cerbo GX.
Sometimes, node-red crashes and restarts:


@4000000067a619e922cf2fac <--- Last few GCs --->
@4000000067a619e922cf377c 
@4000000067a619e922cf3b64 [13222:0x2502f10] 835753808 ms: Scavenge 230.6 (255.7) -> 229.7 (255.7) MB, 2.8 / 0.0 ms  (average mu = 0.973, current mu = 0.977) allocation failure; 
@4000000067a619e922cf4eec [13222:0x2502f10] 835753885 ms: Scavenge 230.6 (255.7) -> 230.0 (255.7) MB, 10.2 / 0.0 ms  (average mu = 0.973, current mu = 0.977) allocation failure; 
@4000000067a619e922cf665c [13222:0x2502f10] 835754017 ms: Scavenge 230.6 (255.7) -> 230.5 (257.7) MB, 41.1 / 0.0 ms  (average mu = 0.973, current mu = 0.977) allocation failure; 
@4000000067a619e922d1d374 
@4000000067a619e922d1d75c 
@4000000067a619e922d1db44 <--- JS stacktrace --->
@4000000067a619e922d1e314 
@4000000067a619e922d1e6fc FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
@4000000067a619e939d876cc *** starting node-red-venus ***
@4000000067a619ea0011e414 *** Waiting for localsettings...
@4000000067a619ea018dd1cc *** Starting in normal mode
@4000000067a619f0018d3974 [info]: loading /data/home/nodered/.node-red/settings-venus.js failed
@4000000067a619f001f21d94 [info]: loading /data/home/nodered/.node-red/settings-user.js failed
@4000000067a619f119e75af4 7 Feb 15:34:15 - [info] 
@4000000067a619f119e77a34 
@4000000067a619f119e78204 Welcome to Node-RED
@4000000067a619f119e785ec ===================
@4000000067a619f119e78dbc 
@4000000067a619f11a5700fc 7 Feb 15:34:15 - [info] Node-RED version: v3.1.10
@4000000067a619f11a85f86c 7 Feb 15:34:15 - [info] Node.js  version: v18.20.3
@4000000067a619f11aa1d53c 7 Feb 15:34:15 - [info] Linux 5.10.109-venus-17 arm LE
@4000000067a619f405c26744 7 Feb 15:34:18 - [info] Loading palette nodes
@4000000067a61a0133ff552c 7 Feb 15:34:31 - [info] Dashboard version 3.2.0 started at /ui

I think the solution would be to add “–max-old-space-size=256” param in
/usr/bin/node-red-venus.sh

exec /usr/bin/node-red $safe --userDir "${NODE_RED}" --max-old-space-size=256 --settings /usr/lib/node_modules/node-red/venus-settings.js "$@"

Test if the setting is applied correctly:

root@einstein:~# node -e "console.log(v8.getHeapStatistics().heap_size_limit / 1024 / 1024 + ' MB')"
257.5 MB

how did you get HTOP on the cerbo gx?

Cerbo HTOP install

1337 :slight_smile:

I updated Cerbo to 3.54 and forgot to lower the heap limit again after the update.
The result was that Node RED crash after about 3 days after the update.

Victron, please change this setting in the official Venus OS release.

It is easy and it just works.
It makes Node RED stable, and also faster, because the kernel has more memory available for the VM cache.

Thank you