ubuntu下 使用AB做压力测试

时间:2023-03-09 00:37:26
ubuntu下 使用AB做压力测试

1最近刚开始接触apache大数据下数据优化,讲一下apache 下ab压力测试工具。

程序“ab”尚未安装。 您可以使用以下命令安装:

apt-get install apache2-utils   

以下是ab --help

sage: 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
-s timeout Seconds to max. wait for each response
Default is 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 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., TLS1. or ALL)
-n :总共的请求执行数,缺省是1;
-c: 并发数,缺省是1;
-t:测试所进行的总时间,秒为单位,缺省50000s
-p:POST时的数据文件
-w: 以HTML表的格式输出结果  

以下为执行    ab -n 5000 -c 200 http://localhost/test.php   的结果:

Benchmarking localhost (be patient)
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Finished requests //执行完的请求次数

Server Software: Apache/2.4.3 //apache版本
Server Hostname: localhost //主机
Server Port: 80 //端口 Document Path: /test.php //路径
Document Length: bytes Concurrency Level:
Time taken for tests: 3.927 seconds //完成此次请求时间
Complete requests: 5000 //完成请求次数
Failed requests: 527 //失败的请求次数
(Connect: , Receive: , Length: , Exceptions: )
Total transferred: bytes //总共传输字节
HTML transferred: bytes
Requests per second: 1273.33 [#/sec] (mean) //每秒请求次数
Time per request: 157.069 [ms] (mean) //一次请求时间
Time per request: 0.785 [ms] (mean, across all concurrent requests)
Transfer rate: 77914.14 [Kbytes/sec] received //传输速率 Connection Times (ms)
min mean[+/-sd] median max
Connect: 73.1
Processing: 143.9
Waiting: 135.3
Total: 160.3 Percentage of the requests served within a certain time (ms)
%
%
%
%
%
%
%
%
% (longest request)