wrk地址:https://github.com/wg/wrk
wrk is a modern HTTP benchmarking tool capable of generating significant load when run on a single multi-core CPU. It combines a multithreaded design with scalable event notification systems such as epoll and kqueue.
wrk使用了epoll(linux)和kqueue(mac)。
安裝(Mac)
brew install wrk
基本使用
1.命令行敲下wrk,可以看到使用幫助
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 <選項> <被測HTTP服務的URL>
Options:
-c, --connections <N> 跟服務器建立并保持的TCP連接數量
-d, --duration <T> 壓測時間
-t, --threads <N> 使用多少個線程進行壓測
-s, --script <S> 指定Lua腳本路徑
-H, --header <H> 為每一個HTTP請求添加HTTP頭
--latency 在壓測結束后,打印延遲統計信息
--timeout <T> 超時時間
-v, --version 打印正在使用的wrk的詳細版本信息
<N>代表數字參數,支持國際單位 (1k, 1M, 1G)
<T>代表時間參數,支持時間單位 (2s, 2m, 2h)
2.看下版本wrk -v/brew info wrk
wrk: stable 4.1.0 (bottled), HEAD
3.做一次簡單壓測,分析下結果
wrk -t12 -c400 -d30s --latency http://www.baidu.com
輸出:
Running 30s test @ http://www.baidu.com
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 933.14ms 415.00ms 2.00s 77.56%
Req/Sec 24.77 15.65 121.00 70.04%
Latency Distribution
50% 711.85ms
75% 1.24s
90% 1.56s
99% 1.90s
8181 requests in 30.10s, 121.83MB read
Socket errors: connect 0, read 0, write 0, timeout 1545
Requests/sec: 271.82
Transfer/sec: 4.05MB
以上使用12個線程400個連接,對baidu首頁進行了30秒的壓測,并要求在壓測結果中輸出響應延遲信息。以下對壓測結果進行簡單注釋:
Running 30s test @ http://www.baidu.com(壓測時間30s)
12 threads and 400 connections(共12個測試線程,400個連接)
Thread Stats Avg Stdev Max +/- Stdev
(平均值) (標準差)(最大值)(正負一個標準差所占比例)
Latency 933.14ms 415.00ms 2.00s 77.56%
(延遲)
Req/Sec 24.77 15.65 121.00 70.04%
(處理中的請求數)
Latency Distribution (延遲分布)
50% 711.85ms
75% 1.24s
90% 1.56s
99% 1.90s (99分位的延遲)
8181 requests in 30.10s, 121.83MB read(30.10秒內共處理完成了8181個請求,讀取了121.83MB數據)
Socket errors: connect 0, read 0, write 0, timeout 1545
Requests/sec: 271.82 (平均每秒處理完成271.82個請求)
Transfer/sec: 4.05MB (平均每秒讀取數據4.05MB)
可以看到,wrk使用方便,結果清晰。并且因為非阻塞IO的使用,可以在普通的測試機上創建出大量的連接,從而達到較好的壓測效果。