The full name of ab is: apache bench. It is the stress testing tool that apache comes with.
1. Install ab
1. linux
yum install apr-util
2. mac
brew install apr-util
2. ab parameter
-n:在测试会话中所执行的请求个数。默认时,仅执行一个请求。
-c:一次产生的请求个数。默认是一次一个。
-t:测试所进行的最大秒数。其内部隐含值是-n 50000,它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。
-p:包含了需要POST的数据的文件。
-P:对一个中转代理提供BASIC认证信任。用户名和密码由一个:隔开,并以base64编码形式发送。无论服务器是否需要(即是否发送了401认证需求代码),此字符串都会被发送。
-T:POST数据所使用的Content-type头信息。
-v:设置显示信息的详细程度-4或更大值会显示头信息,3或更大值可以显示响应代码(404,200等),2或更大值可以显示警告和其他信息。
-V:显示版本号并退出。
-w:以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。
-i:执行HEAD请求,而不是GET。
-x:设置<table>属性的字符串。
-X:对请求使用代理服务器。
-y:设置<tr>属性的字符串。
-z:设置<td>属性的字符串。
-C:对请求附加一个Cookie:行。其典型形式是name=value的一个参数对,此参数可以重复。
-H:对请求附加额外的头信息。此参数的典型形式是一个有效的头信息行,其中包含了以冒号分隔的字段和值的对(如,"Accept-Encoding:zip/zop;8bit")。
-A:对服务器提供BASIC认证信任。用户名和密码由一个:隔开,并以base64编码形式发送。无论服务器是否需要(即,是否发送了401认证需求代码),此字符串都会被发送。
-h:显示使用方法。
-d:不显示"percentage served within XX [ms] table"的消息(为以前的版本提供支持)。
-e:产生一个以逗号分隔的(CSV)文件,其中包含了处理每个相应百分比的请求所需要(从1%到100%)的相应百分比的(以微妙为单位)时间。由于这种格式已经“二进制化”,所以比'gnuplot'格式更有用。
-g:把所有测试结果写入一个'gnuplot'或者TSV(以Tab分隔的)文件。此文件可以方便地导入到Gnuplot,IDL,Mathematica,Igor甚至Excel中。其中的第一行为标题。
-i:执行HEAD请求,而不是GET。
-k:启用HTTP KeepAlive功能,即在一个HTTP会话中执行多个请求。默认时,不启用KeepAlive功能。
-q:如果处理的请求数大于150,ab每处理大约10%或者100个请求时,会在stderr输出一个进度计数。此-q标记可以抑制这些信息。
3. Easy to use and instructions
ab -n 100 -c 100 https://131k.fun/
- 100 requests and 100 requests are processed at the same time
4. Test results and result indicators description
- Test Results
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 131k.fun (be patient).....done
Server Software:
Server Hostname: 131k.fun
Server Port: 443
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES256-GCM-SHA384,2048,256
Server Temp Key: ECDH P-256 256 bits
TLS Server Name: 131k.fun
Document Path: /
Document Length: 21853 bytes
Concurrency Level: 100
Time taken for tests: 20.305 seconds
Complete requests: 100
Failed requests: 0
Total transferred: 2205400 bytes
HTML transferred: 2185300 bytes
Requests per second: 4.92 [#/sec] (mean)
Time per request: 20304.752 [ms] (mean)
Time per request: 203.048 [ms] (mean, across all concurrent requests)
Transfer rate: 106.07 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 83 389 144.0 371 1019
Processing: 238 11973 2631.0 12477 19622
Waiting: 232 11490 2637.7 12015 19614
Total: 322 12362 2650.0 12900 19989
Percentage of the requests served within a certain time (ms)
50% 12900
66% 13646
75% 13891
80% 14133
90% 14476
95% 15367
98% 17334
99% 19989
100% 19989 (longest request)
- Indicator description
Concurrency Level: 100 (并发数)
Time taken for tests: 20.305 seconds (压力测试消耗的总时间)
Complete requests: 100 (压力测试的的总次数)
Failed requests: 0 (失败的请求数)
Total transferred: 2205400 bytes (传输的总数据量)
HTML transferred: 2185300 bytes (HTML文档的总数据量)
Requests per second: 4.92 [#/sec] (mean) (平均每秒的请求数)
Time per request: 20304.752 [ms] (mean) (所有并发用户(这里是100)都请求一次的平均时间)
Time per request: 203.048 [ms] (mean, across all concurrent requests) (单个用户请求一次的平均时间)
Transfer rate: 106.07 [Kbytes/sec] received (传输速率,单位:KB/s)
4. Test case
- Test get interface
ab -n 5000 -c 500 https://131k.fun/
- Test the post interface
ab -n 5000 -c 300 -p post.txt -T 'application/json' https://131k.fun/