稳定性建设之前端最简单的压测工具
背景
node SSR服务上线后出现了内存泄漏问题,我们需要排查和解决。此处需要用到 压测 + 内存监控 + 内存快照 来定位问题
-
内存快照方面,公司有基建的话,直接用,没的话,考虑用heapdump。
-
此文主要是讲前端压测(记录)
前端可以使用的最简单的压测工具
mac上最简单的是:ab,不用下载,直接可以用
其他:
我们可以用 wrk 工具,mac装了 homebrew 后,安装更简单,只需一步,即可使用
- brew install wrk
使用:
-
wrk -t12 -c40 -d30s www.baidu.com
这条命令表示,利用 wrk 对 www.baidu.com 发起压力测试,线程数为 12,模拟 400 个并发请求,持续 30 秒 (请求方法:GET)
参数说明:
-c, --connections: total number of HTTP connections to keep open with
each thread handling N = connections/threads
-d, --duration: duration of the test, e.g. 2s, 2m, 2h 持续时间
-t, --threads: total number of threads to use 线程总数
-s, --script: LuaJIT script, see SCRIPTING 支持跑脚本
-H, --header: HTTP header to add to request, e.g. "User-Agent: wrk" 加请求头
--latency: print detailed latency statistics 打印详细的延迟统计信息
--timeout: record a timeout if a response is not received within this amount of time. 如果在指定时间内未收到响应,则记录超时这段时间
结果
Running 30s test @ http://www.baidu.com (压测时间30s)
12 threads and 400 connections (共12个测试线程,400个连接)
(平均值) (标准差) (最大值)(正负一个标准差所占比例)
Thread Stats Avg Stdev Max +/- Stdev
(延迟)
Latency 386.32ms 380.75ms 2.00s 86.66%
(每秒请求数)
Req/Sec 17.06 13.91 252.00 87.89%
Latency Distribution (延迟分布)
50% 218.31ms
75% 520.60ms
90% 955.08ms
99% 1.93s
4922 requests in 30.06s, 73.86MB read (30.06s内处理了4922个请求,耗费流量73.86MB)
Socket errors: connect 0, read 0, write 0, timeout 311 (发生错误数)
Requests/sec: 163.76 (QPS 163.76,即平均每秒处理请求数为163.76)
Transfer/sec: 2.46MB (平均每秒流量2.46MB)
可以看到,压测报告还是非常直观的!
标准差啥意思?标准差如果太大说明样本本身离散程度比较高,有可能系统性能波动较大。
(相对于另一个常用的压测工具ab来说最大的优点是「支持多线程」)
另外要用更好的工具的话,推荐jmeter
谢谢点赞