Use the V8 profiler
Common commands
Profile can find out the execution time and percentage of specific functions in the entire program to analyze specific code problems. V8 also provides Profile log export commands.
-
Prof provides the execution ratio of each function: node –prof app.js. After executing the command, a *-v8.log file is generated in this directory, and the output of the V8 analyzer can be processed using the command prof-process
-
Cpu-prof includes a more complete call stack and is more readable. node –cpu-prof app.js
Chrome has a tool for analyzing CPU Profile logs. Open Chrome -> DevTools -> More Tools -> JavaScript Profiler -> Load to Load the Cpuprofile file you just generated.
practice
- Sh add the –prof parameter to deploy/entrypoint.sh
REGION=${APP_REGION} DEPLOY_ENV=${ENV} node --prof ./server/dist/src/main.js
Copy the code
- Deploy to the Test environment ((local debug: build before run). After the deployment is successful, you can view it in kubernetes Plaform’s terminal in the form of ISOLATE -0xNNNnnnnnn-v8.log
node --prof-process isolate-0xnnnnnnnnnnnn-v8.log > processed.txt
cat processed.txt
Copy the code
By analyzing Summery in processed. TXT, you first find out where the calls take time and optimize the functions that take time.
Reference links:
- Nodejs.org/en/docs/gui… (Chinese version)
- www.jianshu.com/p/1be0c0fb1…