Memory usage grows steadily

I have a Raspi 4B 8GB onto which I run NodeRed, InfluxDB2, Grafana, Mosquitto and ZigBee2MQTT.
I am not that much into programming or Linux systems management and I am trying to understand why, every now and then, NodeRed slows down to unresponsiveness.
The other processes on the Raspi seem to be still fine when it happens.
I have configured Grafana to keep track of average cpu load and memory usage.
These are the graphs on a time-span of almost 3 days:


it seems that the cpu load doesn't change that much, but the memory usage is steadily increasing overtime.
I tried to understand what to do reading similar issues here on the forum, but still don't know how to check what is happening inside NodeRed.
I use some flow variables, no loops, some subflows and all the variables inside function nodes are declared with "let".
Any help will be appreciated, thanks

What exactly is being used to indicate memory usage? Note that Linux does it's best to use as much memory as possible for disc buffers and so on.

Show us what the output of the command top looks like on startup and after some time.

For the memory and cpu usage I am using the nodered-contrib-os plug-in.
Anyway, below the top output as right now:

and this one is after the reboot I just performed:

So the available memory before the reboot was 5.106GB, so there is no problem with system memory available.

You can also see that node red was using just 3.3% of the memory. It was using quite a lot of CPU both before and after the reboot.

You can see that lxpanel was using a lot of resources. Are you running a browser on the pi? Are you showing charts in the node red dashboard? A common problem that causes slow down of the browser is having charts containing too many data points across the chart. For example, a chart with new data every second and a time span of a day will contain 86400 data points which have to be shuffled down the chart in the browser every second.

I don't use at all the NodeRed dashboard and on the pi there is a browser but I rarely use it.
The pi is an headless one and I connect to it by vnc only when there is the need to change a config, troubleshoot or install updates.
All the other work is made from my laptop (Grafana, InfluxDB, ZigBee2MQTT, NodeRed, etc.)

Was the browser running slow when you rantop before restarting?

Please restart node red in a command window and copy paste the startup log here. Copy/paste the text please, not screenshot.

Hi Colin, as said I don't use the browser on the pi.
Accessing NodeRed from my laptop browser was just fine in terms of response time.
Find below the startup log:

21 Jun 21:38:44 - [info] 

Welcome to Node-RED
===================

21 Jun 21:38:44 - [info] Node-RED version: v3.0.2
21 Jun 21:38:44 - [info] Node.js  version: v18.17.1
21 Jun 21:38:44 - [info] Linux 6.1.21-v8+ arm64 LE
21 Jun 21:38:45 - [info] Loading palette nodes
21 Jun 21:38:47 - [info] Settings file  : /home/rob/.node-red/settings.js
21 Jun 21:38:47 - [info] Context store  : 'memory' [module=memory]
21 Jun 21:38:47 - [info] Context store  : 'harddisk' [module=localfilesystem]
21 Jun 21:38:47 - [info] User directory : /home/rob/.node-red
21 Jun 21:38:47 - [warn] Projects disabled : editorTheme.projects.enabled=false
21 Jun 21:38:47 - [info] Flows file     : /home/rob/.node-red/blackfish_ii.json
21 Jun 21:38:47 - [info] Server now running at http://127.0.0.1:1880/
21 Jun 21:38:47 - [info] Starting flows
21 Jun 21:38:49 - [info] [udp in:Nmea in] udp: port 10110 already in use
21 Jun 21:38:49 - [info] [udp in:Nmea in] udp: port 10110 already in use
21 Jun 21:38:49 - [info] Started flows
21 Jun 21:38:49 - [info] [udp in:Nmea in] udp listener at 0.0.0.0:10110
21 Jun 21:38:49 - [info] [udp in:Nmea in] udp listener at 0.0.0.0:10110
21 Jun 21:38:49 - [info] [udp in:Nmea in] udp listener at 0.0.0.0:10110
21 Jun 21:38:49 - [info] [serialconfig:8e27e2ce1152ad7d] serial port /dev/ttyOP_electron opened at 115200 baud 8N1
21 Jun 21:38:49 - [info] [serialconfig:8b5af2905bea52da] serial port /dev/ttyOP_proton opened at 115200 baud 8N1
21 Jun 21:38:49 - [info] [serialconfig:cdb42694cb23e1ec] serial port /dev/ttyOP_sterstar opened at 19200 baud 8N1
21 Jun 21:38:49 - [info] [serialconfig:6d15e09eb621bb0a] serial port /dev/ttyOP_deckmid opened at 19200 baud 8N1
21 Jun 21:38:49 - [info] [serialconfig:a58a278c51d76967] serial port /dev/ttyOP_deckbow opened at 19200 baud 8N1
21 Jun 21:38:49 - [info] [serialconfig:bf09287eb0dd704b] serial port /dev/ttyOP_sterport opened at 19200 baud 8N1
21 Jun 21:38:49 - [info] [serialconfig:b11328f7fa1eb194] serial port /dev/ttyOP_batshunt opened at 19200 baud 8N1
21 Jun 21:38:49 - [info] [serialconfig:01dfda06ef2a9e0a] serial port /dev/ttyOP_engshunt opened at 19200 baud 8N1
21 Jun 21:38:49 - [info] [serialconfig:f4118db1c0db8014] serial port /dev/ttyOP_lodshunt opened at 19200 baud 8N1
21 Jun 21:38:49 - [info] [serialconfig:6a3cdc3775c4e7d7] serial port /dev/ttyOP_chgshunt opened at 19200 baud 8N1
21 Jun 21:38:49 - [info] [serialconfig:eecba3a00890e897] serial port /dev/ttyOP_bimini opened at 19200 baud 8N1
21 Jun 21:38:49 - [error] 
********************************************************************
Unexpected Node Error
********************************************************************
Info:
 Node object is not a node-red Node
Stack:
 Error: Invalid payload type (undefined): expected number, boolean, string
    at log_helper (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:512:20)
    at Node.error (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:553:9)
    at parsePayload (/home/rob/.node-red/node_modules/node-red-contrib-moving-average/moving-average.js:49:13)
    at MovingAverageNode._inputCallback (/home/rob/.node-red/node_modules/node-red-contrib-moving-average/moving-average.js:64:39)
    at /usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:210:26
    at Object.trigger (/usr/lib/node_modules/node-red/node_modules/@node-red/util/lib/hooks.js:166:13)
    at MovingAverageNode.Node._emitInput (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:202:11)
    at MovingAverageNode.Node.emit (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:186:25)
    at MovingAverageNode.Node.receive (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:485:10)
    at Immediate._onImmediate (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:831:52)

Please report this issue, including the information logged above:
https://github.com/node-red/node-red/issues/
********************************************************************
21 Jun 21:38:49 - [info] [mqtt-broker:MQTT Server] Connected to broker: mqtt://localhost:1883
21 Jun 21:38:50 - [error] 
********************************************************************
Unexpected Node Error
********************************************************************
Info:
 Node object is not a node-red Node
Stack:
 Error: Invalid payload type (undefined): expected number, boolean, string
    at log_helper (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:512:20)
    at Node.error (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:553:9)
    at parsePayload (/home/rob/.node-red/node_modules/node-red-contrib-moving-average/moving-average.js:49:13)
    at MovingAverageNode._inputCallback (/home/rob/.node-red/node_modules/node-red-contrib-moving-average/moving-average.js:64:39)
    at /usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:210:26
    at Object.trigger (/usr/lib/node_modules/node-red/node_modules/@node-red/util/lib/hooks.js:166:13)
    at MovingAverageNode.Node._emitInput (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:202:11)
    at MovingAverageNode.Node.emit (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:186:25)
    at MovingAverageNode.Node.receive (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:485:10)
    at Immediate._onImmediate (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:831:52)

Please report this issue, including the information logged above:
https://github.com/node-red/node-red/issues/
********************************************************************
21 Jun 21:38:51 - [error] 
********************************************************************
Unexpected Node Error
********************************************************************
Info:
 Node object is not a node-red Node
Stack:
 Error: Invalid payload type (undefined): expected number, boolean, string
    at log_helper (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:512:20)
    at Node.error (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:553:9)
    at parsePayload (/home/rob/.node-red/node_modules/node-red-contrib-moving-average/moving-average.js:49:13)
    at MovingAverageNode._inputCallback (/home/rob/.node-red/node_modules/node-red-contrib-moving-average/moving-average.js:64:39)
    at /usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:210:26
    at Object.trigger (/usr/lib/node_modules/node-red/node_modules/@node-red/util/lib/hooks.js:166:13)
    at MovingAverageNode.Node._emitInput (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:202:11)
    at MovingAverageNode.Node.emit (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:186:25)
    at MovingAverageNode.Node.receive (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:485:10)
    at Immediate._onImmediate (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:831:52)

Please report this issue, including the information logged above:
https://github.com/node-red/node-red/issues/
********************************************************************
21 Jun 21:38:52 - [error] 
********************************************************************
Unexpected Node Error
********************************************************************
Info:
 Node object is not a node-red Node
Stack:
 Error: Invalid payload type (undefined): expected number, boolean, string
    at log_helper (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:512:20)
    at Node.error (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:553:9)
    at parsePayload (/home/rob/.node-red/node_modules/node-red-contrib-moving-average/moving-average.js:49:13)
    at MovingAverageNode._inputCallback (/home/rob/.node-red/node_modules/node-red-contrib-moving-average/moving-average.js:64:39)
    at /usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:210:26
    at Object.trigger (/usr/lib/node_modules/node-red/node_modules/@node-red/util/lib/hooks.js:166:13)
    at MovingAverageNode.Node._emitInput (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:202:11)
    at MovingAverageNode.Node.emit (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:186:25)
    at MovingAverageNode.Node.receive (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:485:10)
    at Immediate._onImmediate (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:831:52)

Please report this issue, including the information logged above:
https://github.com/node-red/node-red/issues/
********************************************************************
21 Jun 21:38:53 - [error] 
********************************************************************
Unexpected Node Error
********************************************************************
Info:
 Node object is not a node-red Node
Stack:
 Error: Invalid payload type (undefined): expected number, boolean, string
    at log_helper (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:512:20)
    at Node.error (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:553:9)
    at parsePayload (/home/rob/.node-red/node_modules/node-red-contrib-moving-average/moving-average.js:49:13)
    at MovingAverageNode._inputCallback (/home/rob/.node-red/node_modules/node-red-contrib-moving-average/moving-average.js:64:39)
    at /usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:210:26
    at Object.trigger (/usr/lib/node_modules/node-red/node_modules/@node-red/util/lib/hooks.js:166:13)
    at MovingAverageNode.Node._emitInput (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:202:11)
    at MovingAverageNode.Node.emit (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:186:25)
    at MovingAverageNode.Node.receive (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:485:10)
    at Immediate._onImmediate (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:831:52)

Please report this issue, including the information logged above:
https://github.com/node-red/node-red/issues/
********************************************************************
21 Jun 21:38:54 - [error] [function:starlink?] TypeError: Cannot read properties of undefined (reading 'includes')

Well I would start by sorting out those errors.

You said at the start that sometimes node red is unresponsive. We need to see the CPU and memory usage when that happens. But as I said, sort out the errors first.

See GitHub · Where software is built

I think to have been able to sort the errors out, this is the new startup log:

21 Jun 22:35:34 - [info] 

Welcome to Node-RED
===================

21 Jun 22:35:34 - [info] Node-RED version: v3.0.2
21 Jun 22:35:34 - [info] Node.js  version: v18.17.1
21 Jun 22:35:34 - [info] Linux 6.1.21-v8+ arm64 LE
21 Jun 22:35:34 - [info] Loading palette nodes
21 Jun 22:35:37 - [info] Settings file  : /home/rob/.node-red/settings.js
21 Jun 22:35:37 - [info] Context store  : 'memory' [module=memory]
21 Jun 22:35:37 - [info] Context store  : 'harddisk' [module=localfilesystem]
21 Jun 22:35:37 - [info] User directory : /home/rob/.node-red
21 Jun 22:35:37 - [warn] Projects disabled : editorTheme.projects.enabled=false
21 Jun 22:35:37 - [info] Flows file     : /home/rob/.node-red/blackfish_ii.json
21 Jun 22:35:37 - [info] Server now running at http://127.0.0.1:1880/
21 Jun 22:35:38 - [info] Starting flows
21 Jun 22:35:39 - [info] Started flows
21 Jun 22:35:39 - [info] [udp in:Nmea in] udp listener at 0.0.0.0:10110
21 Jun 22:35:39 - [info] [serialconfig:c7d3c60da272a06b] serial port /dev/ttyOP_electron opened at 115200 baud 8N1
21 Jun 22:35:39 - [info] [serialconfig:70b384990444e19e] serial port /dev/ttyOP_proton opened at 115200 baud 8N1
21 Jun 22:35:39 - [info] [serialconfig:6d15e09eb621bb0a] serial port /dev/ttyOP_deckmid opened at 19200 baud 8N1
21 Jun 22:35:39 - [info] [serialconfig:bf09287eb0dd704b] serial port /dev/ttyOP_sterport opened at 19200 baud 8N1
21 Jun 22:35:39 - [info] [serialconfig:a58a278c51d76967] serial port /dev/ttyOP_deckbow opened at 19200 baud 8N1
21 Jun 22:35:39 - [info] [serialconfig:cdb42694cb23e1ec] serial port /dev/ttyOP_sterstar opened at 19200 baud 8N1
21 Jun 22:35:39 - [info] [serialconfig:f4118db1c0db8014] serial port /dev/ttyOP_lodshunt opened at 19200 baud 8N1
21 Jun 22:35:39 - [info] [serialconfig:6a3cdc3775c4e7d7] serial port /dev/ttyOP_chgshunt opened at 19200 baud 8N1
21 Jun 22:35:39 - [info] [serialconfig:b11328f7fa1eb194] serial port /dev/ttyOP_batshunt opened at 19200 baud 8N1
21 Jun 22:35:39 - [info] [serialconfig:01dfda06ef2a9e0a] serial port /dev/ttyOP_engshunt opened at 19200 baud 8N1
21 Jun 22:35:39 - [info] [serialconfig:eecba3a00890e897] serial port /dev/ttyOP_bimini opened at 19200 baud 8N1
21 Jun 22:35:39 - [info] [mqtt-broker:MQTT Server] Connected to broker: mqtt://localhost:1883

Thanks, read it.
I decided to replace it with another moving average contrib that is more recent.
I checked to find any undefined value passed to the node, but after looking the input for 15 minutes I gave-up and replaced it.

Are you sure it is node-red causing an issue? To me, it looks like something else:

image

lxpanel is using up 24% of your CPU and 20% of your memory. It looks like it is also causing swap activity which, on any pi running from an SD-Card, is a real performance killer.

Yes, yours does not sound like the same problem. When you open the post tell us exactly what the symptom is. What do you see in the node red log?

Hi TotallyInformation,
I have not mentioned it but the pi is running from a 500 GB NVMe SSD disk.

1 Like

Even so, that lxpanel process is sucking up a lot of resources.

Do you know how to debug node processes? If you dont, ask chatgpt how to do it, or google some guide. Run node-red using node --inspect-brk and profile the nemory usage using chrome devtools. I would start by checking if there is a memory leak somewhere caused by one of your nodes, or the runtime.
@pacmanmt

1 Like

So far there has been no evidence that node red is using up memory.

Yes, I am going to investigate on it.
Thank you so much

Thanks for the hint, but this maybe is well over my capabilities.
I normally debug using the debug node placed after the ones to investigate.

Yes, having sorted-out the errors, I am going to keep an eye on the nodered memory usage for a while and definitely try to understand more regarding lxpanel process.
Thank you so much for the help given so far, much appreciated.