Node.js tuning
Introduction
node-profiler
is another product of the alinode team that can help you analyze the performance of JavaScript code offline, presenting the performance details of Google V8 in front of you, and optimizing it. For online tuning, please use alinode
.
Download and Install
It is recommended to install the tool tnvm
, which supports the installation and switching of node, alinode, and profiler.
After the installation is complete, you need to add tnvm as a command-line program. Depending on the platform, it may be ~/.bashrc
, ~/.profile
, or ~/.zshrc
.
Usage Example
If the following appears:
By default, Collect JavaSript CPU Profile is selected, click Start.
You can use the pressure test script to implement pressure testing on the service to ensure more results:
More information about functions during runtime can be seen.
UI Meaning
Red indicates that the function has not been optimized, and light green indicates that the function has been optimized by V8.
Principle Introduction
Based on the built-in sampling collector of V8;
Fixed sampling frequency, default 1ms, configurable;
The main thread is paused, the function call stack is sampled, and the time is counted;
It is necessary to ensure that the sampling is long enough (preheating).
Explanation of two concepts
exclusive time: exclusive time
inclusive time: inclusive time
In this example, the sampling point is in bar()
, so the time consumed by bar
is called exclusive time, and foo
calls bar
, so the time consumed by foo
includes the time of bar
, called inclusive time.
Precautions
This tool currently only supports X64 platforms (Linux, Mac).
Do not deploy it online. If you need online tuning, please use alinode.
Last updated