盘点那些开源的性能测试工具
Posted 转角遇到GitHub
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了盘点那些开源的性能测试工具相关的知识,希望对你有一定的参考价值。
大家好,我是欧盆索思(opensource),每天为你带来优秀的开源项目!
性能测试是通过自动化的测试工具模拟多种正常、峰值以及异常负载条件来对系统的各项性能指标进行测试。负载测试和压力测试都属于性能测试,两者可以结合进行。通过负载测试,确定在各种工作负载下系统的性能,目标是测试当负载逐渐增加时,系统各项性能指标的变化情况。压力测试是通过确定一个系统的瓶颈或者不能接受的性能点,来获得系统能提供的最大服务级别的测试。
今天给大家分享几个性能测试工具。
可能是最知名的:apache 的 ab 工具
ApacheBench,简称 ab,是一个用来衡量 http 服务器性能的单线程命令行工具。原本针对 Apache http 服务器,但是也适用于其他 http 服务器。
ab 工具与标准 Apache 源码一起发布,免费,开源,基于 Apache License。
ab 使用帮助参考:
$ 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 -l Accept variable document length (use this for dynamic pages)
-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
现代的性能测试工具:wrk
为什么说是现代呢?当在多核 CPU 上运行时,能够产生大负载。它结合了多线程设计和可扩展的事件通知系统,例如 epoll 和 kqueue。
基本使用:
wrk -t12 -c400 -d30s http://127.0.0.1:8080/index.html
它使用 12 个线程并保持 400 个 HTTP 连接打开的状态,运行 30 秒基准测试。
输出类似:
Running 30s test @ http://127.0.0.1:8080/index.html
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 635.91us 0.89ms 12.92ms 93.69%
Req/Sec 56.20k 8.07k 62.00k 86.54%
22464657 requests in 30.00s, 17.76GB read
Requests/sec: 748868.53
Transfer/sec: 606.33MB
ab 的替代者,Go 实现的性能测试工具:hey
hey 是一个微型程序,它用于 Web 应用程序的性能测试。
使用帮助参考:
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".
-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 https://baidu.com
输出如下:
Summary:
Total: 18.0569 secs
Slowest: 8.8753 secs
Fastest: 1.1214 secs
Average: 4.2361 secs
Requests/sec: 11.0761
Response time histogram:
1.121 [1] |■
1.897 [2] |■■
2.672 [19] |■■■■■■■■■■■■■■■■
3.448 [48] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
4.223 [39] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
4.998 [41] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
5.774 [18] |■■■■■■■■■■■■■■■
6.549 [12] |■■■■■■■■■■
7.325 [16] |■■■■■■■■■■■■■
8.100 [2] |■■
8.875 [2] |■■
Latency distribution:
10% in 2.6253 secs
25% in 3.1414 secs
50% in 4.0160 secs
75% in 5.0657 secs
90% in 6.5766 secs
95% in 7.1484 secs
99% in 8.2952 secs
Details (average, fastest, slowest):
DNS+dialup: 0.0314 secs, 1.1214 secs, 8.8753 secs
DNS-lookup: 0.0069 secs, 0.0000 secs, 0.0617 secs
req write: 0.0001 secs, 0.0000 secs, 0.0004 secs
resp wait: 1.4666 secs, 0.0895 secs, 4.4198 secs
resp read: 1.3631 secs, 0.0162 secs, 6.4763 secs
Status code distribution:
[200] 200 responses
响应以图表的方式显示,是不是感觉很棒!
文末「阅读原文」可直达项目首页。
今天的项目大家觉得怎么样吗?如果你喜欢,请在文章底部留言、点赞或关注转发,你的支持就是我持续更新的最大动力!
推荐阅读
OpenSourceDaily - 送给爱开源的你
Git · GitHub · GitLab · Gitee
以上是关于盘点那些开源的性能测试工具的主要内容,如果未能解决你的问题,请参考以下文章