CPU Usage spikes - how to identify problems


my node-red sees huge (100%+) CPU usage spikes from time to time. I do have 100+ individual function nodes and > 25 flows, however none of those are complex or justify the cpu usage.

Do you have any hints how to identify the function node or the flow responsible for those?


1 Like

If you are running on Linux try htop, which will show you which processes are using resources.

it is the node-red process - question beeing, how can identify the function within node-red, which is responsible for the high load.

1 Like

I don't think you can directly identify which function is problematic. Try eliminating functions systematically!

Yeah, I'm in the process of that too, just trial and error. I'm actually moving flows over to a new instance since I can't figure out why my old one hangs all the time.

Hey @deme,

Very interesting question!
Would be nice if you could measure the cpu of each Node-RED block, instead of having to use trial-and-error. But I'm not sure whether you can do that, because I 'think' it works like this:

  • A Node-RED block will execute some code (synchronous) => I think you could (somehow) measure the CPU usage required to execute this code.
  • But in that code other code could be called asynchronous => this code will be executed afterwards by the event loop => You would have to measure this CPU usage also, since it has been triggered originally by the Node-RED node.
  • And that previous asynchronous code, can again call another code snippet asynchronously.
  • And so on ...

So you would have to keep track somehow of all code that has been triggered by the Node-RED node, and then sum all those cpu usages to calculate the cpu usage of that Node-RED node. And this process needs to be repeated for all nodes in your flow. Then you would have a nice overview of how much cpu each of your Node-RED nodes uses.

But no idea how to measure that :woozy_face:
I assume you need a CPU profiler. For example if we have a look at the output of this (obsolete!!!) async-profile module:


It seems to me that it keeps track of all asynchronous calls, and at the end all cpu usages are aggregated. But I have never digged into NodeJs cpu profilers...


Digging a bit deeper, apparently, this topic had been discussed / worked on before:

Has someone worked with one of these tools before?

Don't forget this is all running in node.js... When it gets above a certain memory limit (--max-old-space) the garbage cleaner will kick in and try to reclaim the memory. On a small processor with other things going on, this can be quite aggressive and cause spikes. Possibly... or maybe something else.

1 Like

Swapping can also cause big spikes when running off an sd-card. So you should check and get rid of anything not really necessary. Obviously, you won't want to be running a desktop so make sure you stop any desktop related services.