当前位置: 首页 > 工具软件 > Hey > 使用案例 >

压测工具hey介绍

寇桐
2023-12-01

一、介绍

hey 是一个go写的小型程序,用来对网络应用进行压力测试。

二、安装

$ brew install hey

三、使用方法

$ hey
Usage: hey [options...] <url>
 
Options:
    # 请求数量,默认200
  -n  Number of requests to run. Default is 200.
 
    # 同时运行的worker数量,请求总数不能小于并发级别,默认是50
  -c  Number of workers to run concurrently. Total number of requests cannot
      be smaller than the concurrency level. Default is 50.
     
    # 限速比例,每个worker的QPS限制,默认无
  -q  Rate limit, in queries per second (QPS) per worker. Default is no rate limit.
 
    # 应用程序发送请求的持续时间,当达到持续时间时,应用程序停止并退出。 如果指定了持续时间,则忽略参数 n
  -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.
        # 例如:-z 10s -z 3m,意思是持续10s,持续3分钟
 
    # 输出类型,如果未提供,则打印摘要,只支持csv格式,以逗号分隔指标
  -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.
 
    # HTTP请求方法, GET, POST, PUT, DELETE, HEAD, OPTIONS 之一
  -m  HTTP method, one of GET, POST, PUT, DELETE, HEAD, OPTIONS.
 
    # 自定义http header, 多个字段需要添加多个 -H
  -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" .
        #例如: -H "Accept: text/html" -H "Content-Type: application/xml"
 
    # 每个请求的超时时间(以秒为单位),默认值为 20,使用 0 表示无限。
  -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".
  -a  Basic authentication, username:password.
  -x  HTTP Proxy address as host:port.
  -h2 Enable HTTP/2.
 
  -host HTTP Host header.
 
    # 禁用压缩
  -disable-compression  Disable compression.
 
    # 防止在不同 HTTP 请求之间重复使用 TCP 连接
  -disable-keepalive    Disable keep-alive, prevents re-use of TCP
                        connections between different HTTP requests.
 
    # 禁用 HTTP 重定向跟踪
  -disable-redirects    Disable following of HTTP redirects
 
    # 使用的cpu核数,默认16
  -cpus                 Number of used cpu cores.
                        (default for current machine is 16 cores)

四、案例

$ hey -n 2000 -c 50  https://www.baidu.com/
 
Summary:
  # 总运行时长   
  Total:    2.5960 secs
  Slowest:  0.5923 secs
  Fastest:  0.0100 secs
  # 平均响应时间
  Average: 0.0571 secs
  # 每秒响应数(QPS)
  Requests/sec:    770.4025
 
  Total data:   454000 bytes
  Size/request: 227 bytes
 
# 响应直方图
Response time histogram:
  0.010 [1] |
  # 响应时长在0.010~0.068区间的请求总数为1660个   
  0.068 [1660]  |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.126 [126]   |■■■
  0.185 [56]    |■
  0.243 [85]    |■■
  0.301 [41]    |■
  0.359 [18]    |
  0.418 [5] |
  0.476 [3] |
  0.534 [4] |
  0.592 [1] |
 
# http请求时延分布 
Latency distribution:
  10% in 0.0165 secs
  25% in 0.0244 secs
  50% in 0.0333 secs
  75% in 0.0491 secs
  90% in 0.1344 secs
  95% in 0.2141 secs
  # 99时延:满足百分之九十九的网络请求所需要的最低耗时
  99% in 0.3274 secs
 
Details (average, fastest, slowest):
  DNS+dialup:   0.0026 secs, 0.0100 secs, 0.5923 secs
  DNS-lookup:   0.0005 secs, 0.0000 secs, 0.0175 secs
  req write:    0.0000 secs, 0.0000 secs, 0.0014 secs
  resp wait:    0.0508 secs, 0.0099 secs, 0.5922 secs
  resp read:    0.0001 secs, 0.0000 secs, 0.0019 secs
 
# http状态码分布
Status code distribution:
  [200] 2000 responses
 类似资料: