Hey 基于Golang开发的一款类似Ab的压测工具

安装

MaxOS 安装

1
brew install hey

golang源码编译安装

1
go get -u github.com/rakyll/hey

使用示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
> $GOPATH/bin/hey -n 10 -c 10 http://localhost:1313

Summary:
  Total:        0.2637 secs
  Slowest:      0.2627 secs
  Fastest:      0.0480 secs
  Average:      0.1480 secs
  Requests/sec: 37.9278

  Total data:   122950 bytes
  Size/request: 12295 bytes

Response time histogram:
  0.048 [1]     |■■■■■■■■■■■■■■■■■■■■
  0.069 [1]     |■■■■■■■■■■■■■■■■■■■■
  0.091 [1]     |■■■■■■■■■■■■■■■■■■■■
  0.112 [1]     |■■■■■■■■■■■■■■■■■■■■
  0.134 [1]     |■■■■■■■■■■■■■■■■■■■■
  0.155 [0]     |
  0.177 [1]     |■■■■■■■■■■■■■■■■■■■■
  0.198 [1]     |■■■■■■■■■■■■■■■■■■■■
  0.220 [0]     |
  0.241 [1]     |■■■■■■■■■■■■■■■■■■■■
  0.263 [2]     |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■


Latency distribution:
  10% in 0.0604 secs
  25% in 0.0969 secs
  50% in 0.1574 secs
  75% in 0.2416 secs
  90% in 0.2627 secs
  0% in 0.0000 secs
  0% in 0.0000 secs

Details (average, fastest, slowest):
  DNS+dialup:   0.0109 secs, 0.0480 secs, 0.2627 secs
  DNS-lookup:   0.0096 secs, 0.0062 secs, 0.0105 secs
  req write:    0.0002 secs, 0.0000 secs, 0.0009 secs
  resp wait:    0.1367 secs, 0.0360 secs, 0.2524 secs
  resp read:    0.0002 secs, 0.0001 secs, 0.0006 secs

Status code distribution:
  [200] 10 responses

使用帮助

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
> $GOPATH/bin/hey -h
flag needs an argument: -h
Usage: hey [options...] <url>

Options:
  -n  Number of requests to run. Default is 200.
  -c  Number of requests 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). 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".
  -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 4 cores)

参考