node 性能分析

1.使用命令(node自带的profile工具)

node --prof test.js

可以生成性能分析报告,生成一个以isolate-开头的.log文件

分析上述log文件

node --prof-process isolate-开发的.log文件 > profile.txt

就会生成一个profile.txt文件,

node 性能分析

 

 

2.ab压测数据

ab -c50 -t15 http://127.0.0.1:3000/

其中,-c指的是客户端,也就是并发数;-t指的是压测15s;还有一个参数-n 指的是总的请求数

 

3.可以使用chrome devtool

node --inspect-brk test.js

其中brk启动调试的同时,会暂停程序运行

执行命令后,程序进入监听状态

node 性能分析

在浏览器端输入chrome://inspect

node 性能分析

点击页面的inspect按钮,进入工具页,进行调试

node 性能分析

node 性能分析

收集性能数据

上述工具可以配合ab压测

4.使用clinic.js包对nodejs服务进行分析

node 性能分析

提供更多可视化图表进行分析

5.性能优化的准则

a)减少不必要的计算

b)空间换时间

尽量提前计算,将计算放到启动期间