wrk 是一款针对 Http 协议的基准测试工具,它能够在单机多核 CPU 的条件下,使用系统自带的高性能 I/O 机制,如 epoll,kqueue 等,通过多线程和事件模式,对目标机器产生大量的负载。
安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
brew install wrk
wrk -v wrk [kqueue] Copyright (C) 2012 Will Glozer Usage: wrk <options> <url> Options: -c, --connections <N> Connections to keep open -d, --duration <T> Duration of test -t, --threads <N> Number of threads to use -s, --script <S> Load Lua script file -H, --header <H> Add header to request --latency Print latency statistics --timeout <T> Socket/request timeout -v, --version Print version details Numeric arguments may includea SI unit (1k, 1M, 1G) Time arguments may includeatime unit (2s, 2m, 2h)
ab -V 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/
wrk
参数说明
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
% wrk -v wrk [kqueue] Copyright (C) 2012 Will Glozer Usage: wrk <options> <url> Options: -c, --connections <N> Connections to keep open -d, --duration <T> Duration of test -t, --threads <N> Number of threads to use -s, --script <S> Load Lua script file -H, --header <H> Add header to request --latency Print latency statistics --timeout <T> Socket/request timeout -v, --version Print version details Numeric arguments may include a SI unit (1k, 1M, 1G) Time arguments may include a time unit (2s, 2m, 2h)
% ab --help ab: wrong number of arguments 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 -t timelimit Seconds to max. wait for responses -b windowsize Size of TCP send/receive buffer, in bytes -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 for POSTing, 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. -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 (SSL2, SSL3, TLS1, TLS1.1, TLS1.2 or ALL)
% ab -c 300 -t 60 https://hexo.lilis.xin/ 54 ↵ 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/
Concurrency Level: 300# 并发用户数, 这是我们设置的参数之一 Time taken for tests: 60.023 seconds # 所有这些请求被处理完成所花费的总时间 Complete requests: 1803# 总请求数量, 这是我们设置的参数之一 Failed requests: 0# 表示失败的请求数量, 这里的失败是指的请求在连接服务器、发送数据等环节发生异常,以及无响应后超时的情况 Write errors: 0 Total transferred: 60468718 bytes # 所有请求的响应数据长度总和。包括每个HTTP响应数据的头信息和正文数据的长度 HTML transferred: 59089320 bytes # 所有请求的响应数据中正文数据的总和,也就是减去了Total transferred中HTTP响应数据中的头信息的长度 Requests per second: 30.04 [#/sec] (mean) # 吞吐率, 计算公式: Complete requests/Time taken for tests 总请求数/处理完成这些请求数所花费的时间 Time per request: 9987.262 [ms] (mean) # 用户平均请求等待时间, 计算公式: Time token for tests/(Complete requests/Concurrency Level)。处理完成所有请求数所花费的时间/(总请求数/并发用户数) Time per request: 33.291 [ms] (mean, across all concurrent requests) # 服务器平均请求等待时间, 计算公式: Time taken for tests/Complete requests,正好是吞吐率的倒数 Transfer rate: 983.81 [Kbytes/sec] received # 表示这些请求在单位时间内从服务器获取的数据长度
Connection Times (ms) min mean[+/-sd] median max Connect: 48630093112.2221233168 Processing: 22055124516.1451747154 Waiting: 115503883.018318372 Total: 74585215710.0744847759
Percentage of the requests served within a certain time (ms) 50% 7447 66% 9253 75% 10799 80% 11569 90% 15143 95% 19453 98% 25129 99% 29527 100% 47759 (longest request)