hey是 Google一女工程師(現在在aws)使用 Go 語言開發的類似 apache ab 的效能測試工具。相比 ab,boom跨平臺性更好,而且更容易安裝。
hey manual
./bin/hey_linux_amd64 -h
flag needs an argument: -h
Usage: hey [options...] <url>
Options:
-n Number of requests to run. Default is 200.
-c Number of workers to run concurrently. Total number of requests cannot
be smaller than the concurrency level. Default is 50.
-q Rate limit, in queries per second (QPS) per worker. Default is no rate limit.
-z Duration of application to send requests. When duration is reached,
application stops and exits. If duration is specified, n is ignored.
Examples: -z 10s -z 3m.
-o Output type. If none provided, a summary is printed.
"csv" is the only supported alternative. Dumps the response
metrics in comma-separated values format.
-m HTTP method, one of GET, POST, PUT, DELETE, HEAD, OPTIONS.
-H Custom HTTP header. You can specify as many as needed by repeating the flag.
For example, -H "Accept: text/html" -H "Content-Type: application/xml" .
-t Timeout for each request in seconds. Default is 20, use 0 for infinite.
-A HTTP Accept header.
-d HTTP request body.
-D HTTP request body from file. For example, /home/user/file.txt or ./file.txt.
-T Content-type, defaults to "text/html".
-U User-Agent, defaults to version "hey/0.0.1".
-a Basic authentication, username:password.
-x HTTP Proxy address as host:port.
-h2 Enable HTTP/2.
-host HTTP Host header.
-disable-compression Disable compression.
-disable-keepalive Disable keep-alive, prevents re-use of TCP
connections between different HTTP requests.
-disable-redirects Disable following of HTTP redirects
-cpus Number of used cpu cores.
(default for current machine is 8 cores)
舉幾個例子
./bin/hey_linux_amd64 -z 10m http://127.0.0.1:50000
持續發10min無限發壓
./bin/hey_linux_amd64 -c 10 -n 10000 http://127.0.0.1:50000
10併發發10000個請求
程式碼寫的是短小精悍,但唯一是不足是沒法看指標的一個變化曲線,比如我要看服務的效能瓶頸,到達什麼量級系統壓不上去、請求量多少時候機器效能有問題等。因此接入Prometheus + Grafana十分有必要的。
Prometheus 是一個開源的服務監控系統和時間序列資料庫, 提供監控資料儲存,展示,告警等功能。
Grafana 是一個用於監控指標分析和圖表展示的工具, 後端支援 Graphite, InfluxDB & Prometheus & Open-falcon等, 它是一個流行的監控元件, 目前在各大中小型公司中廣泛應用
修改patch
github.com/rickzhen/hey/commit/15e...
如何使用
環境準備可參考
medium.com/geekculture/monitoring-...
注意:忽略blackbox setup步驟
安裝Prometheus
配置prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: "hey"
scrape_interval: 1s
static_configs:
- targets: ['localhost:1010']
注意埠1010是寫死的,後續計劃修改成可以通過命令列進行隨機賦值
- 安裝Grafana
- 引用資料,具體資料項如下
# HELP hey_average_latency hey average lantency of all requests
# TYPE hey_average_latency gauge
hey_average_latency 0.333023128238458
# HELP hey_avg_conn hey average lantency of connection setup(DNS lookup + Dial up)
# TYPE hey_avg_conn gauge
hey_avg_conn 0.0008299568803227264
# HELP hey_avg_delay hey average lantency between response and request
# TYPE hey_avg_delay gauge
hey_avg_delay 0.3276944901389514
# HELP hey_avg_dns hey average lantency of dns lookup
# TYPE hey_avg_dns gauge
hey_avg_dns 0
# HELP hey_avg_req hey average lantency of request "write"
# TYPE hey_avg_req gauge
hey_avg_req 9.923097265800088e-05
# HELP hey_avg_res hey average lantency of response "read"
# TYPE hey_avg_res gauge
hey_avg_res 0.004199986732406999
# HELP hey_fastest hey minimum lantency of all requests
# TYPE hey_fastest gauge
hey_fastest 0.0153465
# HELP hey_fastest_conn hey minimum lantency of connection setup(DNS lookup + Dial up)
# TYPE hey_fastest_conn gauge
hey_fastest_conn 0.0002317
# HELP hey_fastest_delay hey minimum lantency between response and request
# TYPE hey_fastest_delay gauge
hey_fastest_delay 0.007162
# HELP hey_fastest_dns hey minimum lantency of dns lookup
# TYPE hey_fastest_dns gauge
hey_fastest_dns 0
# HELP hey_fastest_req hey minimum lantency of request "write"
# TYPE hey_fastest_req gauge
hey_fastest_req 1.84e-05
# HELP hey_fastest_res hey minimum lantency of response "read"
# TYPE hey_fastest_res gauge
hey_fastest_res 7.03e-05
# HELP hey_num_res hey num of all requests
# TYPE hey_num_res gauge
hey_num_res 2231
# HELP hey_rps hey request of per second
# TYPE hey_rps gauge
hey_rps 148.46734517640908
# HELP hey_slowest_conn hey maximum lantency of connection setup(DNS lookup + Dial up)
# TYPE hey_slowest_conn gauge
hey_slowest_conn 0.0764439
# HELP hey_slowest_delay hey maximum lantency between response and request
# TYPE hey_slowest_delay gauge
hey_slowest_delay 0.6143227
# HELP hey_slowest_dns hey maximum lantency of dns lookup
# TYPE hey_slowest_dns gauge
hey_slowest_dns 0
# HELP hey_slowest_req hey maximum lantency of request "write"
# TYPE hey_slowest_req gauge
hey_slowest_req 0.0123371
# HELP hey_slowest_res hey maximum lantency of response "read"
# TYPE hey_slowest_res gauge
hey_slowest_res 0.1017448
# HELP hey_slowtest hey maximum lantency of all requests
# TYPE hey_slowtest gauge
hey_slowtest 0.6210238
the end
最終效果如下~
選取幾個進行展示
注意:只有hey壓測起來後,才可以採集到相關資料
最後感謝rakyll~
下載地址:github.com/rickzhen/hey/releases
如果對你有幫助的話,辛苦給個star鴨~
如有問題可以提issue,也可以在評論區互相交流。
本作品採用《CC 協議》,轉載必須註明作者和本文連結