wrk 是一款针对 Http 协议的基准测试工具,它能够在单机多核 CPU 的条件下,使用系统自带的高性能 I/O 机制,如 epoll,kqueue 等,通过多线程和事件模式,对目标机器产生大量的负载。
轻量级性能测试工具;
安装简单(相对 Apache ab 来说);
学习曲线基本为零,几分钟就能学会咋用了;
安装对应的软件包
yum install -y gcc git unzip perl perl-devel下载对应的安装包
git clone https://github.com/wg/wrk.git开始安装
cd wrk-master/
make
cp -a wrk /usr/sbin/
[root@Server ~]# wrk -v
wrk [epoll] Copyright (C) 2012 Will Glozer
Usage: wrk <options> <url>
Options:
-c, --connections <N> Connections to keep open
-d, --duration <T> Duration of test
-t, --threads <N> Number of threads to use
-s, --script <S> Load Lua script file
-H, --header <H> Add header to request
--latency Print latency statistics
--timeout <T> Socket/request timeout
-v, --version Print version details
Numeric arguments may include a SI unit (1k, 1M, 1G)
Time arguments may include a time unit (2s, 2m, 2h)开始使用
wrk -t12 -c400 -d30s http://www.baidu.com
wrk -t12 -c400 -d30s --latency http://www.baidu.com第一条命令表示,利用 wrk 对 www.baidu.com 发起压力测试,线程数为 12,模拟 400 个并发请求,持续 30 秒。
第二条压测命令,30 秒压测过后,生成如下压测报告。
[root@Server ~]# wrk -t2 -c40 -d15s --latency http://172.126.9.10:8090
Running 15s test @ http://172.126.9.10:8090
2 threads and 40 connections
(平均值) (标准值) (最大值) (差值)
Thread Stats Avg Stdev Max +/- Stdev
(延迟)
Latency 578.17ms 209.11ms 1.79s 74.08%
(每秒请求数)
Req/Sec 35.68 20.81 138.00 66.30%
Latency Distribution(延迟发布)
50% 537.55ms
75% 686.47ms
90% 859.92ms
99% 1.23s
1026 requests in 15.08s, 83.62MB read
Requests/sec: 68.03 (平均每秒的请求数)
Transfer/sec: 5.54MB (平均每秒流量)可以看到,压测报告还是非常直观的!
评论区