hey 工具小改造

2022-01-20 11:01:40 +08:00
 zgxzgx

hey 工具小改造

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

https://github.com/rickzhen/hey/commit/15e4febda47749aa3683820d705be237ed7d420e

如何使用

环境准备可参考

https://medium.com/geekculture/monitoring-websites-using-grafana-and-prometheus-69ccf936310c

注意:忽略 blackbox setup 步骤

# 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 是写死的,后续计划修改成可以通过命令行进行随机赋值

# 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~

项目地址: https://github.com/rickzhen/hey

下载地址: https://github.com/rickzhen/hey/releases

如果对你有帮助的话,辛苦给个 star 鸭~

如有问题可以提 issue ,也可以在评论区互相交流。

1716 次点击
所在节点    分享创造
4 条回复
danhahaha
2022-01-20 11:51:48 +08:00
900 个 fork ,0 个 star ,第一次见这样的
danhahaha
2022-01-20 11:52:29 +08:00
看错了
pkwenda
2022-01-20 13:45:33 +08:00
@danhahaha #2 恩,他 fork 魔改的
zgxzgx
2022-01-20 19:26:15 +08:00
@pkwenda 对滴

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/829404

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX