Http benchmarking 工具 wrk 基本使用
Http benchmarking 工具 wrk 基本使用
Intro
wrk 是一款現代HTTP基準測試工具,能夠在單個多核CPU上運行時產生顯著負載。它將多線程設計與可擴展事件通知系統(如epoll和kqueue)結合在一起。
官方描述:
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.
An optional LuaJIT script can perform HTTP request generation, response processing, and custom reporting. Details are available in SCRIPTING and several examples are located in?scripts/.
wrk 使用了 epoll,使得可以通過較少的線程來實現較多的連接,而用 ab 測試的時候就會發現很難達到特別高的并發,而 wrk 則利用 i/o 復用來實現較少的線程達到較高的并發。
Install
wrk支持大多數類UNIX系統,不支持windows。需要操作系統支持 LuaJIT 和 OpenSSL,不過不用擔心,大多數類Unix系統都支持。安裝wrk非常簡單,只要從github上下載wrk源碼,在項目路徑下執行 make 命令即可。
在 win10 bash 上安裝參考 :https://www.cnblogs.com/savorboard/p/wrk.html直接在 linux 上安裝參考:https://www.cnblogs.com/jiftle/p/7158291.html
不想安裝也可以直接使用 docker ,參考 williamyeh/wrk
Use
直接使用安裝的 wrk,使用示例如下:
wrk -t 400 -c 4000 --timeout 10s -d 10s --latency http://localhost:12345/api/values
使用 docker
docker run --rm williamyeh/wrk -t 400 -c 4000 --timeout 10s -d 10s --latency http://localhost:12345/api/values
參數詳解:
在 bash 中輸入 wrk 即可獲取到詳細的參數說明:
-c, --connections(連接數): total number of HTTP connections to keep open with each thread handling N = connections/threads
-d, --duration(測試持續時間): duration of the test, e.g. 2s, 2m, 2h
-t, --threads(線程): total number of threads to use
-s, --script(腳本): LuaJIT script, see SCRIPTING
-H, --header(頭信息): HTTP header to add to request, e.g. "User-Agent: wrk"
--latency(響應信息): print detailed latency statistics
--timeout(超時時間): record a timeout if a response is not received within this amount of time.
來對必應做一個測試
wrk -t8 -c200 -d30s --latency "http://www.bing.com"
輸出:
Running 30s test @ http://www.bing.com
8 threads and 200 connections
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
1790465 requests in 30.01s, 684.08MB read
Requests/sec: 59658.29
Transfer/sec: 22.79MB
結果分析:
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)
注:如果 url 不帶 & 參數可以不需要加加引號,如:"url",但是如果有多個get參數有 &則需要加上雙引號才能請求完整的地址,否則會把 & 后面的參數丟失。
Reference
https://hub.docker.com/r/williamyeh/wrk/
https://github.com/wg/wrk
https://cloud.tencent.com/developer/article/1346649
總結
以上是生活随笔為你收集整理的Http benchmarking 工具 wrk 基本使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Excel催化剂插件功能修复与更新汇总篇
- 下一篇: 动手造轮子:实现一个简单的依赖注入(二)