wrk入門總結
-
-
- 一、功能介紹:
- 二、安裝過程:
-
-
- git位址:
- make編譯過程中問題解決:
- 建立軟連結到指定目錄
- 驗證是否安裝成功
-
- 三、wrk 初步使用
-
-
- 基本用法:
-
- 使用方法--readme
- 參數設定經驗
-
- 四 測試場景
-
- 測試HTTP協定網絡的性能
- 測試目前服務的最大QPS
- 使用Lua腳本個性化wrk壓測
-
一、功能介紹:
wrk2是一個主要基于wrk的HTTP基準測試工具,wrk2經過修改後能夠提供穩定的吞吐量負載以及更精确的延時統計,即通過設定參數,wrk2增加了–rate或-R參數設定吞吐量(每秒總請求數)及–u_latency參數顯示延時統計。
二、安裝過程:
wrk安裝過程非常簡單,下載下傳源碼後在項目目錄下執行make指令即可。
-
git位址:
https://github.com/giltene/wrk2# git clone https://github.com/giltene/wrk2.git 下載下傳源碼 # cd wrk2 安裝目錄 # make
-
make編譯過程中問題解決:
1. -bash: make: command not found[[email protected] wrk2-master]# make -bash: make: command not found
系統無法使用make,make install,一般出現== -bash: make: command not found ==的提示,是因為安裝系統的時候使用的是最小化安裝,缺少make、vim等常用指令。
直接安裝make即可解決問題:
安裝g++:
2. src/wrk.h:11:25: fatal error: openssl/ssl.h: No such file or directory
問題在于:系統中缺少openssl庫,安裝即可wrk2入門-http性能壓測工具總結 [[email protected] wrk2-master]# yum install openssl-devel 或者 [[email protected] wrk2-master]# yum install libssl-dev
-
建立軟連結到指定目錄
這一步必須進行設定,否則會出現報錯,-bash: wrk: command not found -
驗證是否安裝成功
make完成後目前路徑下會生成可執行檔案wrk,表示可以使用wrk進行http壓測了。wrk2入門-http性能壓測工具總結
三、wrk 初步使用
-
基本用法:
Basic Usage:wrk <options> <url>
Options: -c, --connections <N> Connections to keep open # HTTP連接配接數,如1k,1M,1G, -d, --duration <T> Duration of test # 測試持續時間,如 2s 2m 2h -t, --threads <N> Number of threads to use # 開啟的線程數 -s, --script <S> Load Lua script file # 進階功能,使用 lua 腳本 -H, --header <H> Add header to request # 添加請求頭 # 列印詳細延遲統計 -L --latency Print latency statistics -U --u_latency Print uncorrceted latency statistics ==# 設定請求逾時時間,大于該時間的請求将被記錄== --timeout <T> Socket/request timeout -B, --batch_latency Measure latency of whole batches of pipelined ops (as opposed to each op) -v, --version Print version details -R, --rate <T> work rate (throughput) #工作速率(吞吐量)即每個線程每秒鐘完成的請求數 in requests/sec (total) [Required Parameter]
- 使用方法–readme
使用方法 | 說明 | 吞吐量/每秒總請求數 |
---|---|---|
wrk -t2 -c100 -d30s -R2000 http://127.0.0.1:8080/index.html | 2個線程,100個連接配接,持續時間30s 每秒2000個請求 | Requests/sec: 2000.12 |
wrk -t2 -c100 -d30s -R2000 --latency url | 2個線程,100個連接配接,持續時間30s,每秒2000個請求 | 延遲辨別,延遲百分比 |
- 參數設定經驗
wrk2入門-http性能壓測工具總結
四 測試場景
-
測試HTTP協定網絡的性能
壓測簡單說明:以上使用了2個線程1000個http連接配接,對baidu進行了15s的壓測,并要求在壓測結果中輸出響應延遲資訊。Running 15s test @ https://www.baidu.com/ ------壓測時間15s 2 threads and 1000 connections -------共2個測試線程,1000個連接配接 Thread calibration: mean lat.: 24.071ms, rate sampling interval: 41ms Thread calibration: mean lat.: 24.373ms, rate sampling interval: 40ms Thread Stats Avg Stdev Max +/- Stdev -----平均值 标準差 最大值 正負一個标準差所占的比例 Latency 13.10ms 5.09ms 124.16ms 95.55% -----延遲 Req/Sec 449.03 706.21 5.15k 94.26% -----進行中的請求數 Latency Distribution (HdrHistogram - Recorded Latency) -----延遲分布 50.000% 12.34ms 75.000% 13.68ms 90.000% 15.83ms -----90分位的延遲 99.000% 21.14ms ----99分位的延遲 99.900% 107.97ms 99.990% 124.22ms 99.999% 124.22ms 100.000% 124.22ms #[Mean = 13.101, StdDeviation = 5.093] #[Max = 124.160, Total count = 2201] #[Buckets = 27, SubBuckets = 2048] ---------------------------------------------------------- 13795 requests in 15.00s, 206.31MB read ----15s内共處理完成了13795個請求,讀取了206.31MB資料 Requests/sec: 919.62 -----平均每秒處理完成919.62個請求 Transfer/sec: 13.75MB -----平均每秒讀取資料13.75MB
-
測試目前服務的最大QPS
進入安裝目錄,運作
通過-R參數擷取吞吐量參數 | 每秒請求量的結果 |
---|---|
./wrk2 -t10 -c50 -d30 -R3000 -H “Host:xxx.com” http://localhost/a/a.mp4 -L | Requests/sec: 3000.12 |
./wrk2 -t10 -c50 -d30 -R5000 -H “Host:xxx.com” http://localhost/a/a.mp4 -L | Requests/sec: 5000.12 |
./wrk2 -t10 -c50 -d30 -R10000 -H “Host:xxx.com” http://localhost/a/a.mp4 -L | Requests/sec: 9800.12 |
./wrk2 -t10 -c50 -d30 -R20000 -H “Host:xxx.com” http://localhost/a/a.mp4 -L | Requests/sec: 12500.12 |
./wrk2 -t10 -c50 -d30 -R30000 -H “Host:xxx.com” http://localhost/a/a.mp4 -L | Requests/sec: 13000.12 |
從以上的測試過程中可以看出,服務最大的每秒請求量為13000,可見性能壓測的QPS為1.3萬左右,考慮本機測試性能損耗問題,即QPS>1.2萬。
-
使用Lua腳本個性化wrk壓測
以上是介紹wrk的安裝及簡單的使用,可以看出wrk的使用較簡單友善,且測試結果清晰,一般情況下關注的名額主要是:90分位延遲、99分位延遲及Requests/sec。但是工作上往往需要較複雜的測試場景,這種簡單的壓測可能就不滿足需求。比如,使用POST 方法跟伺服器互動;每次請求使用不同的參數;為了更好的模拟服務場景,需要使用wrk的script lua腳本來定制壓測過程,即滿足定制化的需求。
有關wrk進階使用方法,可以檢視我的另一篇部落格:wrk2的進階使用方法