http壓測工具wrk使用筆記
阿新 • • 發佈:2018-04-08
wrk安裝wrk
先從github上下載源碼
git clone https://github.com/wg/wrk
然後cd到wrk目錄,make安裝
make
之後即可直接使用,並且再可執行目錄下創建了軟連接 /usr/local/bin/wrk -> /usr/local/src/wrk/wrk
wrk的基本使用
先看一下wrk的幫助
wrk --help Usage: wrk <options> <url> Options: ? ?-c, --connections <N> Connections to keep open #跟服務器建立並保持TCP連接數量,設置壓測並發連接數 ? ?-d, --duration ? <T> Duration of test ?##壓測時間 ? ?-t, --threads ? <N> Number of threads to use ?##指定壓測的線程數 ? ?-s, --script ? ? <S> Load Lua script file ?##可指定Lua腳本進行http壓測,待詳細研究 ? ?-H, --header ? ? <H> Add header to request ?##為每一個HTTP請求添加HTTP頭,???怎麽加呢 ? ? ? ?--latency ? ? ? ? Print latency statistics ?##打印出延時分布的概率:Latency Distribution ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?50% ? ?1.10ms ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?75% ? ?2.23ms ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?90% ?83.63ms ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?99% ?482.18ms ? ? ? ?--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)
<N>表示數值參數,支持國際單位(1k, 1M, 1G)
<T> 表示時間參數,支持時間單位(2s, 2m, 2h)
查看wrk版本,可發現wrk使用epoll機制
wrk -v
wrk 4.1.0 [epoll] Copyright (C) 2012 Will Glozer
壓測一個內網HTTP服務
設置5個線程1000個連接測試,並在壓測結果中輸出響應延遲的信息
wrk -c1000 -t5 http://192.168.0.105:80 --latency --timeout 1s Running 10s test @ http://192.168.0.105:80 ? 5 threads and 1000 connections ? Thread Stats? Avg? ? ? Stdev? ? Max? +/- Stdev ? ? Latency? ? 26.28ms? 84.56ms 839.47ms? 91.76% ? ? (延遲時間) ? ? Req/Sec? ? 7.52k? ? 3.56k? 30.09k? ? 76.06% ? ? (每秒處理的請求數) ? Latency Distribution ? ? 50%? ? 1.31ms? (50%請求子啊1.31ms返回) ? ? 75%? ? 2.63ms? (75%請求子啊2.63ms返回) ? ? 90%? 51.78ms (90%請求子啊51.78ms返回) ? ? 99%? 407.39ms(99%請求子啊407.39ms返回) ? 369586 requests in 10.03s, 299.23MB read (10.03s內處理369586個請求,讀取684.08MB數據) ? Socket errors: connect 0, read 19, write 0, timeout 139(請求異常數量) Requests/sec:? 36858.65 (平均每秒處理完成請求數) Transfer/sec:? ? 29.84MB (平均每秒傳輸數據大小)
wrk通過簡單的命令行可以壓測簡單的GET請求,但要壓測PUT、POST等更復雜的http服務,還可通過Lua腳本定制壓測過程,待實踐後補充。
http壓測工具wrk使用筆記