[ANNOUNCE] node-red-contrib-v8-cpu-profiler: beta

Hi folks,

I saw tonight a discussion about CPU usage being 100% at irregular moments, which makes it very hard to figure out the root cause. Because:

  • Since you don't know when it happens you cannot simply start a profiling, because you cannot let the profiling run for e.g. 3 days.
  • Since we don't have continious profiling, like professional tools (e.g. Dynatrace) offer.

So I thought: suppose we could start/stop cpu profiling from within a custom node. Then you can start/stop cpu profiling :

  • Manually by injecting control messages.
  • Automatically e.g. when the measured cpu (e.g. via my node-red-contrib-cpu node). This way you could start the profiling automatically as soon as cpu goes to 100%, doesn't matter when that happens ...

So I quickly wrote my first new node of 2022: node-red-contrib-v8-cpu-profiler :partying_face: :clinking_glasses: :champagne:

This node allows you to generate a .cpuprofile file, which can be visualized via third party tools as a flame graph (e.g. via Chrome Developer tools as explained in my wiki).

Since I have not spend much time on this node, most probably I might have forgotten some things. So it would be nice if some users could test it, before I publish it on npm. You can install it directly from my Github repository (from within your .node-red) folder:

npm install bartbutenaers/node-red-contrib-v8-cpu-profiler

As usual, all "constructive" feedback is very welcome!!

Bart

8 Likes

Hey Bart,

thanks a lot, I installed the module. Is it enough to place it in a single flow? Do I need any input/output connections (e.g. an inject?)?

Where can I find the .cpuprofile file? Is it written to ./node-red?

I can give you feedback probably tomorrow. :slight_smile:

Okay, I answered most of the questions by reading your github page ... :wink:

Hi Mathias,

  • Yes a single node is enough, since it connects to the Google V8 Javascript engine (that runs your NodeJs server). So it will profile ALL the Javascript code that is being executed in your NodeJs instance.

  • On my readme page you can find an example flow, which shows how to start/stop the profiling via an Inject node manually. However I assume you don't know when cpu will be getting high, so you cannot start the profiling manually? In that case you could e.g. use my node-red-contrib-cpu node to measure the cpu continiously. And you could feed the cpu usage value into the node-red-contrib-value-for node, to determine that the cpu is e.g. between 95% and 100% for N minutes. If that is the case you can (once!!) start the profiling for N seconds (as you can configure on my node's config screen). The profile should be long enough to get good statistical information.

  • When you import my example flow, you will see that the last node in the flow is a FileWrite node. In my case the profile json is stored in my temp folder:

    image

    Of course you can choose whatever folder you like...

1 Like

I got an output - it worked so far. I could import it into the chrome dev tools.

Thank you very much for this node - now I just need some expertise to interpret the data. =P

Yes indeed it is not very easy to start with interpreting flame graphs. I have added a few tips on my wiki, but I am not an expert in this.
If you find anything useful, please share it so I can add it to the wiki...
Or if you have any doubts, just share it here also!

Based on the feedback from @IAmKonni, I have completely rewritten my wiki tutorial. It now explains a step-by-step about how to find the root cause of high CPU usage in a Node-RED flow.

5 Likes

I have added two new features:

  • When a profile is complete, it will be send on a first output. But when a profile is interrupted prematurely, it will be send on a second output.
  • The output message now contains both the startTimestamp and endTimestamp.

These changes allowed me to write a new tutorial on the wiki about "Create a profile for high CPU usage at unpredictable times". Summarized: when the CPU usage is above 90% for 5 seconds, then it tries over and over again to record a CPU profile of 10 seconds long. That way users should be capable of profiling peaks that they cannot profile manually.

Version 1.0.0 is good enough for me as an initial version:

image

3 Likes