Usage: wrk <options> <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的詳細版本 Numeric arguments may include a SI unit (1k, 1M, 1G) Time arguments may include a time unit (2s, 2m, 2h)
例如: html
wrk -t8 -c200 -d30s --latency "http://www.bing.com"
Running 30s test @ http://www.bing.com (壓測時間30s) 8 threads and 200 connections (共8個測試線程,200個鏈接) Thread Stats Avg Stdev Max +/- Stdev (平均值) (標準差)(最大值)(正負一個標準差所佔比例) Latency 46.67ms 215.38ms 1.67s 95.59% (延遲) Req/Sec 7.91k 1.15k 10.26k 70.77% (處理中的請求數) Latency Distribution (延遲分佈) 50% 2.93ms 75% 3.78ms 90% 4.73ms 99% 1.35s (99分位的延遲) 1790465 requests in 30.01s, 684.08MB read (30.01秒內共處理完成了1790465個請求,讀取了684.08MB數據) Requests/sec: 59658.29 (平均每秒處理完成59658.29個請求) Transfer/sec: 22.79MB (平均每秒讀取數據22.79MB)
wrk -t1 -c4 -d100s -T3s --script=post.lua --latency http://localhost:8080/xtopic/newsjava
post.lua腳本文件
paramArr = {} falg = 0 -- 初始化 function init(args) for line in io.lines("requestParams.txt") do //requestParams.txt 請求參數文件 print(line) paramArr[falg] = line falg = falg+1 end end -- 請求 function request() local headers = { } headers['Content-Type'] = "application/json" body = paramArr[math.random(0,table.getn(paramArr))] return wrk.format("POST",nil,headers,body) end -- 響應 function response(status,headers,body) if(status ~= 200) then print("response===error",status,body) else print("response===success",status,body) end end
wrk中執行http請求的時候,調用lua分爲3個階段,setup,running,done,每一個wrk線程中都有獨立的腳本環境json