Apache安装包中自带的压力测试工具Apache Benchmark(简称ab)简单易用,这里采用ab作为压国测试工具.
独立安装:
ab运行需要信赖apr-util包:
# yum install apr-util
安装信赖yum-utils中的yumdownload工具如果没有找到yumdownload
# yum install yum-utils
安装完成执行以下指令
[root@localhost opt]# cd /opt/
[root@localhost opt]# mkdir abtmp
[root@localhost opt]# cd abtmp/
[root@localhost abtmp]# yum install yum-utils.noarch
[root@localhost abtmp]# yumdownloader httpd-tools*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors..com
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
httpd-tools-2.4.-.el7.centos..x8 | kB :
[root@localhost abtmp]# ls
httpd-tools-2.4.-.el7.centos..x86_64.rpm
安装:
[root@localhost abtmp]# rpm -ihv httpd-tools-2.4.-.el7.centos..x86_64.rpm
Preparing... ################################# [%]
Updating / installing...
:httpd-tools-2.4.-.el7.centos. ################################# [%]
下面对NGINX做测试:
# ab -n -c100 123.57.36.227/index.html
This is ApacheBench, Version 2.3 <$Revision: $>
Copyright Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 123.57.36.227 (be patient)
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Finished requests #处理1000个请求 Server Software: nginx/1.6.
Server Hostname: 123.57.36.227
Server Port: Document Path: /index.html
Document Length: bytes #与Tomcat请求页面的节数大小一致 Concurrency Level:
Time taken for tests: 2.539 seconds
Complete requests:
Failed requests:
Write errors:
Total transferred: bytes
HTML transferred: bytes
Requests per second: 393.82 [#/sec] (mean)#吞吐量:393.82/s
Time per request: 253.920 [ms] (mean)#每个请求的平均处理时间
Time per request: 2.539 [ms] (mean, across all concurrent requests)
Transfer rate: 93.07 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 308.8
Processing: 126.9
Waiting: 126.9
Total: 337.1 Percentage of the requests served within a certain time (ms)
%
%
%
% 213#80%的请求在213ms之内完成
%
%
%
%
% (longest request)#1624ms完成100%的请求
下面对tomcat做测试:
# ab -n 1000 -c100 123.57.36.227:8080/index.jsp
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 123.57.36.227 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests # Server Software: Apache-Coyote/1.1
Server Hostname: 123.57.36.227
Server Port: 8080 Document Path: /index.jsp
Document Length: 13 bytes Concurrency Level: 100
Time taken for tests: 4.101 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 254000 bytes
HTML transferred: 13000 bytes
Requests per second: 243.84 [#/sec] (mean)
Time per request: 410.111 [ms] (mean)
Time per request: 4.101 [ms] (mean, across all concurrent requests)
Transfer rate: 60.48 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 2 46 201.0 4 1007
Processing: 3 266 610.4 68 3232
Waiting: 3 255 609.2 57 3232
Total: 6 312 628.6 83 3238 Percentage of the requests served within a certain time (ms)
50% 83
66% 149
75% 217
80% 295
90% 1010
95% 1449
98% 3164
99% 3191
100% 3238 (longest request)
对比两数值除理1000个请求tomcat所用的时间是nginx的(3238/1624=1.99)2倍时间!