NodeJS provides a built-in profiler which allows developer to analyse and optimise their code. Official documentation and in-depth details can be found here.
- Start WebUI server that is to be investigated with:
node --prof index.js
- Execute for a few times at an interval the user scenarios that are suspected to be causing a big stress on the server. During this time, NodeJS will automatically create and update a file with the analysis details while the server is running.
- Once done, stop the server.
- Use the NodeJS generated log file prefixed with
isolate-
to get a report of the activities by running:node --prof-process isolate-<rest_of_log_file_name>.log > processed.txt
- Open the
processed.txt
file in your preferred editor, analyse the[Summary]
section and identifyComponents/Sub-Sections
that have a high number ofticks
or increased percentage from the total. - Proceed to analyse sub-sections that appear to be taking lots of resources.