hey 壓測小工具

今天介紹一個 Go 開發的小工具 hey,它可以根據你的需求向 web 服務器發送請求,並統計請求詳情。
hey 是一個開源項目。
github 地址爲:https://github.com/rakyll/hey
二進制文件下載地址:

Mac 安裝

brew install hey

Hey 可以併發地向服務端發起請求,並打印統計數據。下面看看使用方法:

Usage: hey [options...] <url>

Options:
  -n  發起請求數. 默認200.
  -c  併發數. 併發數不能比請求數大. 默認50.
  -q  每個併發worker發送請求速率,即(QPS)每秒發送請求數,默認沒有限制。
  -z  發送請求持續時間. 時間到了就退出.設置了持續時間, 請求數就會被忽略,到時間才停止發請求. 例如:-z 10s -z 3m.
  -o  輸出格式. 如果沒有提供,則打印彙總.還支持csv輸出。
  -m  HTTP方法, 包括:GET, POST, PUT, DELETE, HEAD, OPTIONS.
  -H  自定義HTTP請求頭. 您可以重複該標誌來指定所需的header數量。
     例如, -H "Accept: text/html" -H "Content-Type: application/xml" .
  -t  每個請求的超時時間(以秒爲單位). 默認是20, 0無期限.
  -A  HTTP Accept標頭.
  -d  HTTP請求體.
  -D  HTTP請求正文爲文件, 例如: /home/user/file.txt or ./file.txt.
  -T  Content-type, 默認"text/html".
  -a  基本認證, username:password.
  -x  HTTP Proxy 格式: host:port.
  -h2 使用 HTTP/2.

  -host HTTP Host header.

  -disable-compression 禁用壓縮.
  -disable-keepalive    禁用keep-alive, 不同請求使用不同TCP連接.
  -disable-redirects    禁用HTTP重定向
  -cpus                 併發使用的cpu核數 (當前機器的默認值是8核)

下面演示一個簡單的 GET 請求,看看效果:

hey -m GET -c 2 -n 10  "http://www.baidu.com"
Summary:




Total:    0.3606 secs  
Slowest:  0.1496 secs  
Fastest:  0.0399 secs 
Average:  0.0707 secs
Requests/sec: 27.7288


Response time histogram:




0.040 [1] |■■■■■■■■■■
  0.051 [4] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■  0.062 [0] |
  0.073 [3] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■  0.084 [0] |
  0.095 [0] |
  0.106 [0] |
  0.117 [0] |
  0.128 [0] |
  0.139 [0] |
  0.150 [2] |■■■■■■■■■■■■■■■■■■■■


Latency distribution:
  10% in 0.0400 secs
  25% in 0.0465 secs
  50% in 0.0629 secs
  75% in 0.1478 secs
  90% in 0.1496 secs
  0% in 0.0000 secs
  0% in 0.0000 secs

Details (average, fastest, slowest):
  DNS+dialup:   0.0136 secs, 0.0399 secs, 0.1496 secs
  DNS-lookup:   0.0080 secs, 0.0000 secs, 0.0400 secs
  req write:    0.0000 secs, 0.0000 secs, 0.0001 secs
  resp wait:    0.0321 secs, 0.0296 secs, 0.0354 secs
  resp read:    0.0249 secs, 0.0093 secs, 0.0488 secs

Status code distribution:
  [200] 10 responses

可以看到,命令執行結果顯示:

另一個 python 開發的壓測工具,帶有前端頁面的可以參考:https://github.com/locustio/locust 開源項目

本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源https://mp.weixin.qq.com/s/CBMjGsNI9Fm9Ym1U7g_2Gw