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)
簡(jiǎn)單翻成中文:
使用方法: wrk <選項(xiàng)> <被測(cè)HTTP服務(wù)的URL>
Options:
-c, --connections <N> 跟服務(wù)器建立并保持的TCP連接數(shù)量
-d, --duration <T> 壓測(cè)時(shí)間
-t, --threads <N> 使用多少個(gè)線程進(jìn)行壓測(cè)
-s, --script <S> 指定Lua腳本路徑
-H, --header <H> 為每一個(gè)HTTP請(qǐng)求添加HTTP頭
--latency 在壓測(cè)結(jié)束后,打印延遲統(tǒng)計(jì)信息
--timeout <T> 超時(shí)時(shí)間
-v, --version 打印正在使用的wrk的詳細(xì)版本信息
<N>代表數(shù)字參數(shù),支持國(guó)際單位 (1k, 1M, 1G)
<T>代表時(shí)間參數(shù),支持時(shí)間單位 (2s, 2m, 2h)
2.看下版本wrk -v/brew info wrk
wrk: stable 4.1.0 (bottled), HEAD
3.做一次簡(jiǎn)單壓測(cè),分析下結(jié)果
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個(gè)線程400個(gè)連接,對(duì)baidu首頁(yè)進(jìn)行了30秒的壓測(cè),并要求在壓測(cè)結(jié)果中輸出響應(yīng)延遲信息。以下對(duì)壓測(cè)結(jié)果進(jìn)行簡(jiǎn)單注釋?zhuān)?/p>
Running 30s test @ http://www.baidu.com(壓測(cè)時(shí)間30s)
12 threads and 400 connections(共12個(gè)測(cè)試線程,400個(gè)連接)
Thread Stats Avg Stdev Max +/- Stdev
(平均值) (標(biāo)準(zhǔn)差)(最大值)(正負(fù)一個(gè)標(biāo)準(zhǔn)差所占比例)
Latency 933.14ms 415.00ms 2.00s 77.56%
(延遲)
Req/Sec 24.77 15.65 121.00 70.04%
(處理中的請(qǐng)求數(shù))
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秒內(nèi)共處理完成了8181個(gè)請(qǐng)求,讀取了121.83MB數(shù)據(jù))
Socket errors: connect 0, read 0, write 0, timeout 1545
Requests/sec: 271.82 (平均每秒處理完成271.82個(gè)請(qǐng)求)
Transfer/sec: 4.05MB (平均每秒讀取數(shù)據(jù)4.05MB)
可以看到,wrk使用方便,結(jié)果清晰。并且因?yàn)榉亲枞鸌O的使用,可以在普通的測(cè)試機(jī)上創(chuàng)建出大量的連接,從而達(dá)到較好的壓測(cè)效果。