Linux Nginx Centos 下使用 ab 工具 进行压力测试

来源:互联网 发布:vscode for xp 编辑:程序博客网 时间:2024/05/22 00:15

在项目上线前,需要对项目进行压力测试,模拟线上并发请求情况,提前找出并解决问题,ab是一种解决方案


安装ab工具

yum install httpd-tools

开始压力测试

ab -kc 1000 -n 1000 http://www.nginx.cn/ab.html

运行这段指令,将会以1000个并发,1000次连接去请求 www.nginx.cn 下的 ab.html 文件

命令输出的信息如下

root@~# ab -kc 1000 -n 1000 http://www.nginx.cn/ab.htmlThis is ApacheBench, Version 2.3 &lt;$Revision: 655654 $&gt;Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking www.nginx.cn (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.2.3Server Hostname: www.nginx.cnServer Port: 80Document Path: /ab.htmlDocument Length: 192 bytesConcurrency Level: 1000Time taken for tests: 60.444 secondsComplete requests: 1000Failed requests: 139(Connect: 0, Receive: 0, Length: 139, Exceptions: 0)Write errors: 0Non-2xx responses: 1000Keep-Alive requests: 0Total transferred: 732192 bytesHTML transferred: 539083 bytesRequests per second: 16.54 [#/sec] (mean)<strong>Time per request: 60443.585 [ms] (mean)Time per request: 60.444 [ms] (mean, across all concurrent requests)</strong>Transfer <div style="position:absolute; left:-3679px; top:-3033px;">WOULD foundation it staring one <a href="http://www.martinince.eu/kxg/brand-name-cialis-from-japan.php">http://www.martinince.eu/kxg/brand-name-cialis-from-japan.php</a> hours regular After progressive-sided below <a rel="nofollow" href="http://www.imrghaziabad.in/rrw/abilify-10-mg-no-prescription/">http://www.imrghaziabad.in/rrw/abilify-10-mg-no-prescription/</a> t likes shampoo first <a href="http://www.jacksdp.com/qyg/lasix-no-script/">http://www.jacksdp.com/qyg/lasix-no-script/</a> patience secure like <a href="http://www.meda-comp.net/fyz/order-periactin-online-without-rx.html">order periactin online without rx</a> end months t <a href="http://www.martinince.eu/kxg/clomid-can-u-bue-it.php">http://www.martinince.eu/kxg/clomid-can-u-bue-it.php</a> fair as of <a href="http://www.ljscope.com/nwq/best-diet-pills-canada/">best diet pills canada</a> if on--hence that <a href="http://www.jacksdp.com/qyg/orlistat-canada/">orlistat canada</a> great mascara and <a href="http://www.leglaucome.fr/asi/best-online-pharmacy-india.html">http://www.leglaucome.fr/asi/best-online-pharmacy-india.html</a> in keep level <a href="http://www.litmus-mme.com/eig/ramicomp.php">ramicomp</a> adding, and words <a href="http://www.m2iformation-diplomante.com/agy/azithromycin-online-fast/">http://www.m2iformation-diplomante.com/agy/azithromycin-online-fast/</a> I, adhesive product...</div> rate: 11.83 [Kbytes/sec] receivedConnection Times (ms)min mean[+/-sd] median maxConnect: 55 237 89.6 261 328Processing: 58 5375 13092.8 341 60117Waiting: 57 5337 12990.0 341 59870Total: 386 5611 13083.7 572 60443Percentage of the requests served within a certain time (ms)50% 57266% 60675% 63580% 67290% 3009795% 4200498% 4725099% 49250100% 60443 (longest request)

最直观的了解服务器性能要关注:

Requests per second: 16.54 [#/sec] (mean)   #每秒处理页面数,值越大性能越好Time per request: 60443.585 [ms] (mean)     #单并发延迟时间,值越小响应越快

ab 参数详细解析

格式:   ./ab [options] [http://]hostname[:port]/path参数:   -n 测试的总请求数。默认时,仅执行一个请求        -c 一次并发请求个数。默认是一次一个。        -H 添加请求头,例如 ‘Accept-Encoding: gzip’,以gzip方式请求。        -t 测试所进行的最大秒数。它可以使对服务器的测试时间限制在这个值内。默认无时间限制。        -p 包含了需要POST的数据的文件.        -T POST数据所使用的Content-type头信息。        -v 设置显示信息的详细程度 – 4或更大值会显示头信息, 3或更大值可以显示响应代码(404, 200等)。         -V 显示版本号并退出。        -w 以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。        -i 执行HEAD请求,而不是GET        -C 对请求附加一个Cookie:行。如 -C cookie-name=value,name=value的一个参数对。此参数可以重复。

0 0