ab命令会创建多个并发访问线程,模拟多个访问者同时对某一URL地址进行访问。它的测试目标是基于URL的,因此,它既可以用来测试apache的负载压力,也可以测试nginx、lighthttp、tomcat、IIS等其它Web服务器的压力
[root@n9e ~]# yum provides abLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.comhttpd-tools-2.4.6-93.el7.centos.x86_64 : Tools for use with the Apache HTTP ServerRepo : baseMatched from:Filename : /usr/bin/ab[root@n9e ~]#
[root@n9e ~]# yum install httpd-tools -yLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.comResolving Dependencies--> Running transaction check---> Package httpd-tools.x86_64 0:2.4.6-93.el7.centos will be installed--> Finished Dependency ResolutionDependencies Resolved===============================================================================================================================Package Arch Version Repository Size===============================================================================================================================Installing:httpd-tools x86_64 2.4.6-93.el7.centos base 92 kTransaction Summary===============================================================================================================================Install 1 PackageTotal download size: 92 kInstalled size: 168 kDownloading packages:httpd-tools-2.4.6-93.el7.centos.x86_64.rpm | 92 kB 00:00:02Running transaction checkRunning transaction testTransaction test succeededRunning transactionInstalling : httpd-tools-2.4.6-93.el7.centos.x86_64 1/1Verifying : httpd-tools-2.4.6-93.el7.centos.x86_64 1/1Installed:httpd-tools.x86_64 0:2.4.6-93.el7.centosComplete![root@n9e ~]#
[root@n9e ~]# ab -helpUsage: ab [options] [http[s]://]hostname[:port]/pathOptions 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 benchmarkingThis implies -n 50000-s timeout Seconds to max. wait for each responseDefault 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 attributesare a colon separated username and password.-P attribute Add Basic Proxy Authentication, the attributesare 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)[root@n9e ~]#
[root@n9e ~]# ab -c 100 -n 1000 http://10.182.220.135/This is ApacheBench, Version 2.3 <$Revision: 1430300 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking 10.182.220.135 (be patient)Completed 100 requestsCompleted 200 requestsCompleted 300 requestsCompleted 400 requestsCompleted 500 requestsCompleted 600 requestsCompleted 700 requestsCompleted 800 requestsCompleted 900 requestsCompleted 1000 requestsFinished 1000 requestsServer Software: nginx/1.16.1Server Hostname: 10.182.220.135Server Port: 80Document Path: /Document Length: 350 bytesConcurrency Level: 100Time taken for tests: 1.343 secondsComplete requests: 1000Failed requests: 0Write errors: 0Total transferred: 583000 bytesHTML transferred: 350000 bytesRequests per second: 744.40 [#/sec] (mean)Time per request: 134.337 [ms] (mean)Time per request: 1.343 [ms] (mean, across all concurrent requests)Transfer rate: 423.81 [Kbytes/sec] receivedConnection Times (ms)min mean[+/-sd] median maxConnect: 4 20 63.0 16 1012Processing: 4 16 5.7 15 30Waiting: 4 15 5.7 15 29Total: 8 36 62.2 33 1018Percentage of the requests served within a certain time (ms)50% 3366% 3375% 3380% 3490% 3495% 3598% 3899% 42100% 1018 (longest request)[root@n9e ~]#
Server Software: nginxServer Hostname: 127.0.0.1Server Port: 80Document Path: /wordpressDocument Length: 178 bytes #请求大小Concurrency Level: 10000 #并发请求量Time taken for tests: 7.926 seconds #整个测试持续时间Complete requests: 100000 #完成的请求数Failed requests: 0 #失败的请求数Write errors: 0Non-2xx responses: 100000Total transferred: 36800000 bytes #整个场景中网络传输量HTML transferred: 17800000 bytes #整个场景中的HTML内容传输量Requests per second: 12615.91 [#/sec] (mean) #吞吐速率,大家最关心的指标之一Time per request: 792.650 [ms] (mean) #用户平均请求等待时间,大家最关心的指标之二Time per request: 0.079 [ms] (mean, across all concurrent requests) #服务器平均请求处理的时间,大家最关心的指标之三Transfer rate: 4533.84 [Kbytes/sec] received #平均每秒网络上的流量,可以帮助排除是否有存在网络流量过大导致响应时间延长的问题Connection Times (ms)min mean[+/-sd] median maxConnect: 0 510 1056.6 3 7026Processing: 3 28 89.9 8 1889Waiting: 0 25 89.4 6 1887Total: 7 538 1079.8 12 7240Percentage of the requests served within a certain time (ms)50% 1266% 2275% 101680% 102290% 123195% 302798% 323299% 3828100% 7240 (longest request)
