Linux上Node.js项目性能测试实操指南
一、测试流程与分层
二、常用负载与基准测试工具
ab -c 100 -t 30 http://localhost:3000wrk -t12 -c400 -d30s http://localhost:3000autocannon -c 100 -d 30 http://localhost:3000artillery quick -n 1000 -c 10 http://localhost:3000三、运行时与系统层性能分析
四、实操示例与命令清单
node --inspect server.js(便于随时接入 DevTools 分析)curl -I http://localhost:3000/healthab -c 100 -t 30 http://localhost:3000/wrk -t12 -c400 -d30s http://localhost:3000/autocannon -c 100 -d 30 http://localhost:3000/scripts/load-test.yml:config:
target: "http://localhost:3000"
phases:
- duration: 60
arrivalRate: 50
- duration: 120
arrivalRate: 100
scenarios:
- name: "Health check"
flow:
- get:
url: "/health"
artillery run scripts/load-test.ymlpm2 monit(观察 CPU/内存/事件循环),pm2 logs(实时日志)node --prof app.js → 结束后 node --prof-process isolate-*.log > processed.txtclinic flame -- node app.jsnpm i heapdump;在代码中 require('heapdump'); heapdump.writeSnapshot('./heap-$(date +%s).heapsnapshot')五、结果解读与优化方向