Node-RED is overloading the CPU

Node-RED keeps the CPU usage close to 100% most of the time, even when there are no flows. I removed the component along with all its settings and reinstalled it. I didn’t see anything in the logs indicating a problem.

The issue started sometime last autumn, but I don’t know the exact time. Initially, I suspected it was caused by Home Assistant version updates and hoped that a future update would fix it, but the problem persists. Do anyone have any ideas on how to resolve this?

Versions:

Maybe it is not configured correctly to interact with HA, like a missing access token, but such things should be listed in the addon’s logs.
Also make sure the palettes in Node Red are up to date for all the HA ones.

“I installed Node-RED as an add-on and haven’t changed any settings. I only set the log level to trace, hoping that something indicating the problem would appear there. I also haven’t managed any tokens. If you install Node-RED on a clean Home Assistant setup, it works without issues even without any configuration.”

Maybe something happened to the access token or it was not removed when the old installation was removed.
Try to uninstall Node Red and purge any configuration.
Then click your user in HA and select the security tab and see if there is an access token for Node Red.
If there is then remove it and then reinstall the Node Red addon.

I don’t see any long lived access tokens. I also checked my other Home Assistant installation where Node-RED doesn’t overload the CPU, and there are no long lived tokens there either. But there are some refresh tokens, there is qite few information, eg:
Created 3 days ago
Last used 3 days ago from 2001:7d0:840b:ee00:3db0:af17:72c9:97aa
Expires in 3 months

It’s not clear what they were created for.

Strange.
I have a long-lived access token for Node-Red.

Long-lived access tokens are only required for Node-RED running on a separate machine (and other clients that require inbound access to HA and/or an add-on). When NR is installed as an add-on it uses the controlling supervisor to proxy between containers and no tokens are required.

Short-term tokens are auto generated to support web browser access on the local network. HA does not permit access to anything without first logging in, which generates these tokens.

In terms of NR hogging the CPU -

NR runs under node.js as single-thread. node is normally very robust except when it runs out of memory and the garbage collector takes over. If node is hogging the CPU then NR would not be running, so assuming NR is actually working, that is not the problem.

Node-RED, as the main runtime, runs the execution engine to run the flows, and the server. Flows execute by handing over to the JS in each node to run the node, and NR waits until the node finishes. Hence any node that gets stuck will hog the execution (and NR). There is an element of asynchronous processing where nodes can return control to the execution queue, but remain alive eg waiting for an http call return. Badly behaved nodes will not tidy up and kill promises and timers, which can be an issue on redeployment when running flows need to be shutdown and recreated.

The NR server supports the editor (which runs in another machine browser), and there may well be other server configuration nodes running also. These may have keep-alive. My Modbus Server nodes go to sleep, as does the HA WebSocket server, but some provide a ‘keep alive’ heart beat option. Generally the servers should be quiescent between actual use.

If NR is responsive, and no flows are running, yet the CPU is consumed, my assumption would be that node is ok, the execution queue is ok, but that a server is hogging in the background. So, perhaps going through the configuration node list and disabling each ‘server’ node to see if that is the cause.

Of course, looking at my machine, the one component not yet mentioned that comes to mind is the HA installed Node Red Companion, currently v4.1.2 (updated to v4+ middle of last year). This probably communicates back and forth with the HA (WebSocket) server, and between them they deal with registering new entities with HA. If your companion requires updating it may be that, on start up, the HA server and companion are attempting to re-register all the NR created entities, are having issues, and are just going around in circles.

After that, I have absolutely no idea.

I have only one server node, when I disable it,CPU drops to 0. And also I did following actions and get logs:

  1. Uninstall previous Node Red with all setting
  2. Install new NR
  3. Changes in settings: ssl: false, log_level: trace
  4. Start NR: CPU is overloaded
  5. In “Configuration nodes” is only one node “Server: Home Assistant”, after disabling it 09:35:00, CPU drops to 0.
  6. 09:48:27 delete this server node, CPU remains 0
  7. 09:51:47 import previous flows and there is on server node “Home Assistant”, CPU is overloaded
  8. 09:58:04 disable this server node: CPU drops 0, all flows are running, but with errors where is communication with HA (read sensor, write …, etc)

Maybe its related (problem arises at similar time), that I cant use correctly NR UI through HA (myhost:8123/a0d7b954_nodered/ingress), because some functionality does not work. But directly to NR (myhost:1880/#flow/c58a12f74a5ea0xx) works well.

Maybe in logs are some hints: 2025-02-18 HA Node Red.log - Google Drive

So your one server node is the standard HA WebSocket Home Assistant server.

And we know that this is the thing hogging the CPU, and probably because it is continually attempting to either connect or to pass information back and forth.

As you have Node-RED as an HA add-on: the inbound connection to the Node-RED editor is most likely a separate (and common) issue. The standard <ip address>:1880 should work and the editor should be responsive.

Your logs are extensive. I can’t see anything particular, just lots of things going on. When you disable the HA server with the flows then this solves the issue, but that does not indicate if the issue is the HA server not working correctly or just being too busy doing stuff.

To much going on:- if you have an 'Events: ’ node installed then this will listen to the HA event bus, and it must be correctly configured so as to only listen for as little as possible. Listening to too much will overload the WebSocket.

If you have the CPU issue with the HA server, but with no flows running (are you sure there is nothing running?) then this must be a config error. Have you checked the Node RED companion integration version? If this is old it can be a cause of connection issues with the HA server.

I imported flows in point 7 (09:51:47). All the previous logs describes situation without flows.

I have been also tested different versions of NR Companion - no difference. Some days all system worked without NR Companion and also same result - CPU is overloaded, all flows worked with lag, only NR UI through HA was affected.

Debugging this will take time.

I suggest (it is only a suggestion) that you start with no flows, and a working system.

Add one HA websocket node (eg poll an entity state) and the HA server, and test that this works. Thus showing that the HA server is OK and not overloaded at this point. This means that the problem is something is doing too much (in a loop or thrashing).

Then add back the flows - but disable each one by disabling the triggers (and perhaps also disabling the WebSocket nodes themselves). If you can go through each flow in turn. My guess (it is only a guess) is that there is one flow with something that is overloading the WebSocket, or going around in a loop.

The quickest way to do this is a binary-chop.
No flow = no problem.
All flows = problem.
Turn off half - no problem, must be this half : problem still, must be other half
Turn off half of the problem half… etc

I don’t understand - I have problem without flows. Check first four points on my previous post.

I no understand either:

  1. Uninstall NR
  2. Install new NR
  3. Change settings ssl off, log-level trace
  4. In configuration nodes only one - server Home Assistant; disable CPU drops to 0

so, if you have a blank NR install, why is the HA server there to start with? I guess that the standard NR add-on comes with a standard HA server node.

If you disable this and the problem goes away, then it is the HA server configuration setting or connection back to HA.

If you delete the HA server with no flows - can you add back one WebSocket node, and then add back the one new HA server configuration node, and test this?

For the HA add-on the HA Server node setting is ‘Using the Home Assistant Add-on’

There is not much else to change - you can try ‘Delay Connection Attempts’.

I don’t normally generate extensive logs, but I find

“homeassistant”:“2023.3.0”

in your output. I don’t know if this is a dependency requirement or the actual HA installed, but you say you have 2025.02.1 - clearly HA from 2023 will not work and would possibly explain the issue.

After that - I am all out of ideas

ChatGPT think that 2023.3.0 is minimum HA version for current NR version. I make some experiments from backup and a brand new HA install on another hardware.

Have you tried reinstalling Node-RED Companion Integration?

Yes, I tried reinstalling and using different NR Companion versions, but it had no effect.

I installed a fresh Home Assistant on another Raspberry Pi and manually loaded the history, Lovelace and Energy Dashboard configurations, YAML files for configuration and automations, etc. On this newly set up system, Node-RED works flawlessly and does not overload the CPU.

If no new ideas come up soon, I will give up and set up a new HA manually tomorrow.

If anyone has a reference to a guide on how this should be done correctly (without using backups), I would appreciate it.

When you uninstall the NodeRed addon, do you also purge the settings?

I recently screwed up my install and need to reinstall NR. First export all your flows. Then go to the configuration page of the addon, switch to yaml and copy the config settings. This is only necessary if you needed to add certain packages as shown below.

Next I navigated from a file browser on another machine to the location where the media folder is, you should also see a folder called add on config. There is a nodered folder in there, copy it off ha. Then uninstall the addon and flick the switch to delete all NR data.

Reboot the host not just HA and reinstall NR. Update the addon config if necessary and import your flows. If you installed additional nodes you will need to reinstall them. Once everything is working make a backup and you can delete that old NR folder.

The new HA installation has been running for two days now. The NR container’s CPU usage stays close to zero as it should, and memory usage remains between 160-190MiB. In the problematic situation, memory usage fluctuated between 300 and 900MiB.

It’s great that everything is working now as expected. It’s unfortunate that I never found out what was causing the high CPU load.