My Node-RED flow feels heavy on Raspberry Pi 4

Hello everyone! I am a new user in using Node-RED :smiley:

I want to ask something about Node-RED on my Raspberry Pi 4 which feels heavy and as a result makes my dashboard feel delayed (for example when using a switch, when pressed it does not react immediately, but waits a few seconds when pressed it reacts).

The following is the flow that I made:
v1flows.json (61.7 KB)

Is there any way to make the flow lighter?

Are you running the browser on the pi?

Run the command top and see what processes are consuming the CPU.

Does it run ok after a restart and get slower over time?

Hi Colin, thanks for your reply :grinning:

Yes, I am running Chromium on the Pi to open both the flow editor and the Node-RED dashboard. So when I run Node-RED, I will open my Chromium to see the dashboard.

Here is a screenshot of my Pi's task manager when the flow is fully running (all sensors are sending their readings at the same time) and the dashboard is open as well.

But with 1 note, for the following screenshot, it is already in a state where the time interval for sending sensor readings is 1 minute (but I captured the screen when all sensors sent their readings, so the CPU used became larger), not a 3-second interval like my flow that I previously sent. Actually, by changing it to a 1-minute interval, what happens is that the response (for example) of the switch becomes better unlike before when the interval for sending sensor readings was 3 seconds.

So, I can say that the real burden is when the sensors actually send their readings together. Because when the sensor readings have been sent, CPU usage goes down and if I use a switch, it will immediately respond without delay. Delay only occurs when the sensor is sending its readings to be displayed. (This happens at 1 minute intervals, for 3 second intervals it feels like it will always be delayed all the time)

I don't think you answered that.

Please set it up so that the browser response is slow and show us what top looks like then. Top in a command window please, not task manager.

Oh, okay.
Sorry, I misunderstood your instructions

Here I attach 2 videos, for the first video I run the flow while opening the dashboard on Chromium which then runs the "top" command. For the first video I tried also restarting the Node-RED and I showed how the effect was in "top", then I tried also after that restarting the Pi and immediately running the "top" command.

Video 1

For the second video, I immediately ran the "top" command without running my flow, then I tried restarting the Pi and running the "top" command again.

Video 2

Please just post a screenshot showing what top looks like when the system is running slow. I have not got time to wade through videos.

Also you still have not answered the question, is it ok on a restart and then gets worse over time, or is it the same straight after restart?

Okay, this is the screenshot

It is same straight after restart the flow

Well you have plenty of memory, and swap has not been used, so it is not that.

It is, however, thrashing the CPU. My pi 4 consumes usually less than 1% CPU and my Pi 3B reading and passing on about 12 sensors, many at 1 sec sampling, is running at less than 10%.

Something in your flows is therefore consuming a lot of processor time, which is consistent with your description of the problem. The problem is, trying to work out exactly where the bottleneck is.

If you shutdown the browser and watch top does it make much difference to the node-red usage?

What does the command sudo iotop show? It should show you whether any processes are held up by SD card access, though that would not normally cause a lot of CPU usage.

One approach to tracking it down is to disable flow tabs to try and work out what the problem is.

Which node are you using for the ds18b20 access? node-red-contrib-something possibly.

1 Like

What size are the CSV files you are logging to in /home/kamalpi/Datalog/?

Are you rotating them?

the fact you are trying to write to 11 CSV files every 3 seconds (without any sequencing) is a red flag for me.

In 1 hour, there would be:
20 updates/minute * 60 minutes = 1200 updates/hour per file

And in 24 hours:
1200 updates/hour * 24 hours = 28800 updates/day per file

And taking one of your examples, you appear to be writing something like: { time: '15/04/2024, 16:39:47', 'TDB EA': 1234 }\n each time. That equates to around 1.5MB per file per day.

This is data that really should be in a database (probably a timeseries database)

1st step:

  • disable all the file writes - does it behave better?
  • Cascade, sequence or group the operations - does it behave better?


  • Replace file writes with database


My screenshot above may look different to your Node-RED. I replaced all the blynk and PRI nodes with function nodes otherwise your flow looks like this :point_down: for me and others - something to be mindful of when exporting flows for others to look at.

1 Like

Not a solution but running the node-red server on pi and using the node-red dashboard on the PC/laptop browser will take some load off the pi I suppose?
EDIT: I am of course assuming you have a laptop or a PC in the same network as pi.

Thanks for all the replies, I really appreciate it.

Colin, when I turned off my browser and looked at how it responded to "top", I noticed there is very little difference in red-node usage. It only dropped about 7%, from 60% to 53%.

Then regarding the command "sudo iotop", this command is not detected on my pi

Regarding the type of node I use for DS18B20, the one I use is node-red-contrib-sensor-ds18b20 0.2.0 (node-red-contrib-sensor-ds18b20 (node) - Node-RED)

I have also tried to disable some nodes and continue to try per node type to find out where the problem is. But when I did that, I didn't find where the problem was, because it still lags. I just assumed that because there were a lot of processes and they were done in 3-second intervals, the system would feel heavy. I tried changing it to a 1-minute interval, and the result was quite good because I didn't experience lag like before. If it happens, it's only briefly and not continuously like when I set it in 3 second intervals. Maybe this is one of the solutions, or is there something else I can do to get better results?

Steve, for the size of my CSV files for now that have bagged for the largest file has 13212 data, the size reaches 632.8 kb. Actually, I avoided separate CSV files for datalogging, I actually prefer to use only 1 CSV file but already covers all my measuring points, but the problem is that I don't know how to modify the nodes and code so that it can be realized, so in the end I made separate files for each measuring point.

Regarding the rotation question, I honestly don't understand. What does rotation mean? I'm sorry, but maybe you could explain what it means?

Then about disabling all writing to CSV files, I've done it, but the result still feels heavy (in 3-second time intervals), as well as staggering like the one you described, it still lags. However, I tried changing all the time intervals to 1 minute and got better results than before. There is no continuous lag, with this 1-minute time interval, if there is a lag, it is only at times when the sensors actually send their readings simultaneously, but after that the system will return to normal and not lag continuously.

Regarding cascade, sequence or group the operations, sorry but I don't understand how to do that, or can you please give me an example of doing it?

Trexnickel, I agree with your statement that when we run the node-red server on the pi and run a separate dashboard on the PC/laptop, it will reduce the load on the pi. However, the tool that I made requires the use of the server and dashboard on the same device, namely on the pi, so I can't do that...

I imagine that an internet search for How it install iotop on a pi would rapidly have led you to the command
sudo apt install iotop

In that case the nodes you have disabled are not responsible for the issue.

I have a number of sensors running at that rate, some at 1 second intervals. You should not be seeing such a high CPU usage with the system you describe.

So the CSV writing is not the problem. In that case do not worry about installing iotop.

Okay, thank you very much for all the explanations :wink: