wrk
# 安装
git clone https://github.com/wg/wrk && cd wrk && make && cp wrk /usr/local/bin/
使用方法: wrk <选项> <被测HTTP服务的URL>
Options:
-c, --connections <N> 跟服务器建立并保持的TCP连接数量
-d, --duration <T> 压测时间
-t, --threads <N> 使用多少个线程进行压测
-s, --script <S> 指定Lua脚本路径
-H, --header <H> 为每一个HTTP请求添加HTTP头
--latency 在压测结束后,打印延迟统计信息
--timeout <T> 超时时间
-v, --version 打印正在使用的wrk的详细版本信息
<N>代表数字参数,支持国际单位 (1k, 1M, 1G)
<T>代表时间参数,支持时间单位 (2s, 2m, 2h)
wrk使用例子
# wrk -t8 -c200 -d30s --latency "http://www.bing.com"
Running 30s test @ http://www.bing.com
8 threads and 200 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 2.94ms 5.71ms 414.75ms 99.80%
Req/Sec 9.02k 414.37 9.78k 79.31%
Latency Distribution
50% 2.79ms
75% 3.03ms
90% 3.30ms
99% 4.39ms
2155050 requests in 30.10s, 646.91MB read
Requests/sec: 71597.89 (平均每秒处理完成71597.89个请求)
Transfer/sec: 21.49MB
ab
# 安装
yum install -y httpd-tools
参数n为请求的次数,c为一次请求的并发次数 t为请求时间
# ab -h
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make at a time
-t timelimit Seconds to max. to spend on benchmarking
This implies -n 50000
-s timeout Seconds to max. wait for each response
Default is 30 seconds
-b windowsize Size of TCP send/receive buffer, in bytes
-B address Address to bind to when making outgoing connections
-p postfile File containing data to POST. Remember also to set -T
-u putfile File containing data to PUT. Remember also to set -T
-T content-type Content-type header to use for POST/PUT data, eg.
'application/x-www-form-urlencoded'
Default is 'text/plain'
-v verbosity How much troubleshooting info to print
-w Print out results in HTML tables
-i Use HEAD instead of GET
-x attributes String to insert as table attributes
-y attributes String to insert as tr attributes
-z attributes String to insert as td or th attributes
-C attribute Add cookie, eg. 'Apache=1234'. (repeatable)
-H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
Inserted after all normal header lines. (repeatable)
-A attribute Add Basic WWW Authentication, the attributes
are a colon separated username and password.
-P attribute Add Basic Proxy Authentication, the attributes
are a colon separated username and password.
-X proxy:port Proxyserver and port number to use
-V Print version number and exit
-k Use HTTP KeepAlive feature
-d Do not show percentiles served table.
-S Do not show confidence estimators and warnings.
-q Do not show progress when doing more than 150 requests
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-r Don't exit on socket receive errors.
-h Display usage information (this message)
-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
-f protocol Specify SSL/TLS protocol
(SSL3, TLS1, TLS1.1, TLS1.2 or ALL)
ab使用例子
重点关注Requests per second
和Time per request
指标,分别是每秒请求数和单个请求耗时。
# ab -n 1000 -c 100 http://localhost/index.html
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/1.10.1
Server Hostname: localhost
Server Port: 80
Document Path: /index.html
Document Length: 12 bytes
Concurrency Level: 100 ###并发数
Time taken for tests: 0.301 seconds ###共使用了多少时间
Complete requests: 1000 ###请求数
Failed requests: 0 ###失败数
Write errors: 0
Total transferred: 263538 bytes
HTML transferred: 13068 bytes
Requests per second: 3324.49 [#/sec] (mean) ###每秒多少请求,这个是非常重要的参数数值,服务器的吞吐量
Time per request: 30.080 [ms] (mean) ##用户平均请求等待时间
Time per request: 0.301 [ms] (mean, across all concurrent requests) ##服务器平均处理时间,也就是服务器吞吐量的倒数
Transfer rate: 855.60 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 9 13 2.2 13 18
Processing: 9 14 2.5 15 27
Waiting: 0 7 3.1 7 16
Total: 22 28 2.6 27 41
Percentage of the requests served within a certain time (ms)
50% 27 50%的请求在27ms内返回
66% 29 60%的请求在29ms内返回
75% 29
80% 30
90% 31
95% 31
98% 32
99% 41
100% 41 (longest request)
hey
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 8 cores)
hey使用例子
# hey -n 1000 -c 200 http://www.weibo.com
Summary:
Total: 1.5331 secs
Slowest: 1.0570 secs
Fastest: 0.0535 secs
Average: 0.1049 secs
Requests/sec: 652.2805
Response time histogram:
0.053 [1] |
0.154 [797] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.254 [62] |■■■
0.355 [139] |■■■■■■■
0.455 [0] |
0.555 [0] |
0.656 [0] |
0.756 [0] |
0.856 [0] |
0.957 [0] |
1.057 [1] |
Latency distribution:
10% in 0.0587 secs
25% in 0.0608 secs
50% in 0.0642 secs
75% in 0.0729 secs
90% in 0.2701 secs
95% in 0.2787 secs
99% in 0.2905 secs
Details (average, fastest, slowest):
DNS+dialup: 0.0203 secs, 0.0535 secs, 1.0570 secs
DNS-lookup: 0.0037 secs, 0.0000 secs, 0.0400 secs
req write: 0.0002 secs, 0.0000 secs, 0.0125 secs
resp wait: 0.0487 secs, 0.0413 secs, 0.0755 secs
resp read: 0.0002 secs, 0.0001 secs, 0.0036 secs
Status code distribution:
[200] 1000 responses