日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Http benchmarking 工具 wrk 基本使用

發布時間:2023/12/4 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 基本使用的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。