ApacheBench是apache自带的ab程序,可以实现对Apache或其他web服务器的性能压力测试。
ab会并发创建很多个现成来模拟多个用户同时对url进行访问。ab命令对发出负载的计算机要求很低,既不会占用很高CPU,也不会占用很多内存,但却会给目标服务器造成巨大的负载。
常用的命令格式举例:
ab -n 5000 -c 1000 url
-n后面的4000代表总共发出4000个请求;-c后面的1000表示采用1000个并发(模拟1000个人同时访问),后面的网址表示测试的目标URL。
执行结果:
07:29 [root@IP]$ ab -n 2000 -c 100 http://www.xxx.com/a/id_XMTM5NDY0.html This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking ding.youku.com (be patient) Completed 200 requests Completed 400 requests Completed 600 requests Completed 800 requests Completed 1000 requests Completed 1200 requests Completed 1400 requests Completed 1600 requests Completed 1800 requests Completed 2000 requests Finished 2000 requests Server Software: nginx Server Hostname: ding.youku.com Server Port: 80 Document Path: /a/id_XMTM5NDY0.html Document Length: 17412 bytes Concurrency Level: 100 Time taken for tests: 2.268 seconds Complete requests: 2000 Failed requests: 2 (Connect: 0, Receive: 0, Length: 2, Exceptions: 0) Write errors: 0 Non-2xx responses: 2 Total transferred: 35543234 bytes HTML transferred: 34817778 bytes Requests per second: 881.67 [#/sec] (mean) Time per request: 113.421 [ms] (mean) concurrency *timetaken * 1000 / done Time per request: 1.134 [ms] (mean, across all concurrent requests) timetaken * 1000 / done Transfer rate: 15301.47 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 2 4 2.9 3 21 Processing: 25 70 184.8 30 2050 Waiting: 22 38 82.4 25 1225 Total: 27 74 186.3 32 2070 Percentage of the requests served within a certain time (ms) 50% 32 66% 34 75% 35 80% 37 90% 42 95% 267 98% 781 99% 1182 100% 2070 (longest request)
网络环境对测试结果影响比较大,单台服务器情况下在本机测试,或者在局域网中对服务器集群进行测试,结果会更准确一些。
如有疑问欢迎随时讨论,请大家多指点,谢谢!