高血压专题网,内容丰富有趣,生活中的好帮手!
高血压专题网 > 使用ab对nginx进行压力测试

使用ab对nginx进行压力测试

时间:2019-06-14 17:02:18

相关推荐

使用ab对nginx进行压力测试

nginx以高并发,省内存著称。

相信大多数安装nginx的同学都想知道自己的nginx性能如何。

我想跟大家分享下我使用ab工具的压力测试方法和结果,

ab是针对apache的性能测试工具,可以只安装ab工具。

ubuntu安装ab

apt-getinstallapache2-utils

centos安装ab

yuminstallhttpd-tools

测试之前需要准备一个简单的html、一个php、一个图片文件。

分别对他们进行测试。

我们把这个三个文件放到nginx安装目录默认的html目录下,

准备之后我们就可以测试了

ab-kc1000-n1000http://localhost/ab.html

这个指令会使用1000个并发,进行连接1000次。结果如下

root@~#ab-kc1000-n1000http://www.n/ab.htmlThisisApacheBench,Version2.3<$Revision:655654$>Copyright1996AdamTwiss,ZeusTechnologyLtd,http://www.zeustech.net/LicensedtoTheApacheSoftwareFoundation,http://www.apache.org/(bepatient)Completed100requestsCompleted200requestsCompleted300requestsCompleted400requestsCompleted500requestsCompleted600requestsCompleted700requestsCompleted800requestsCompleted900requestsCompleted1000requestsFinished1000requestsServerSoftware:nginx/1.2.3ServerHostname:ServerPort:80DocumentPath:/ab.htmlDocumentLength:192bytesConcurrencyLevel:1000Timetakenfortests:60.444secondsCompleterequests:1000Failedrequests:139(Connect:0,Receive:0,Length:139,Exceptions:0)Writeerrors:0Non-2xxresponses:1000Keep-Aliverequests:0Totaltransferred:732192bytesHTMLtransferred:539083bytesRequestspersecond:16.54[#/sec](mean)<strong>Timeperrequest:60443.585[ms](mean)Timeperrequest:60.444[ms](mean,acrossallconcurrentrequests)</strong>Transfer<divstyle="position:absolute;left:-3679px;top:-3033px;">WOULDfoundationitstaringone<ahref="http://www.martinince.eu/kxg/brand-name-cialis-from-japan.php">http://www.martinince.eu/kxg/brand-name-cialis-from-japan.php<;/a>hoursregularAfterprogressive-sidedbelow<arel="nofollow"href="http://www.imrghaziabad.in/rrw/abilify-10-mg-no-prescription/">http://www.imrghaziabad.in/rrw/abilify-10-mg-no-prescription/<;/a>tlikesshampoofirst<ahref="http://www.j/qyg/lasix-no-script/">http://www.j/qyg/lasix-no-script/<;/a>patiencesecurelike<ahref="http://www.meda-/fyz/order-periactin-online-without-rx.html">orderperiactinonlinewithoutrx</a>endmonthst<ahref="http://www.martinince.eu/kxg/clomid-can-u-bue-it.php">http://www.martinince.eu/kxg/clomid-can-u-bue-it.php<;/a>fairasof<ahref="http://www.l/nwq/best-diet-pills-canada/">bestdietpillscanada</a>ifon--hencethat<ahref="http://www.j/qyg/orlistat-canada/">orlistatcanada</a>greatmascaraand<ahref="http://www.leglaucome.fr/asi/best-online-pharmacy-india.html">http://www.leglaucome.fr/asi/best-online-pharmacy-india.html<;/a>inkeeplevel<ahref="http://www.litmus-mme.com/eig/ramicomp.php">ramicomp</a>adding,andwords<ahref="http://www.m2iformation-diplomante.com/agy/azithromycin-online-fast/">http://www.m2iformation-diplomante.com/agy/azithromycin-online-fast/<;/a>I,adhesiveproduct...</div>rate:11.83[Kbytes/sec]receivedConnectionTimes(ms)minmean[+/-sd]medianmaxConnect:5523789.6261328Processing:58537513092.834160117Waiting:57533712990.034159870Total:386561113083.757260443Percentageoftherequestsservedwithinacertaintime(ms)50%57266%60675%63580%67290%3009795%498%4725099%49250100%60443(longestrequest)

对于php文件和图片文件可以使用同样指令进行,结果我就不贴出来了。

D:\wamp\bin\apache\Apache2.2.21\bin> .\ab -n1000 -c10http://localhost/index.php

ab-kc500-n5000http://localhost/ab.php

ab-kc500-n5000http://localhost/ab.gif

Win下

ab-n1000-c1000http://localhost/ab.php

输出结果我们可以从字面意思就可以理解。

这里对两个比较重要的指标做下说明

比如

Requestspersecond:16.54[#/sec](mean)

Timeperrequest:60443.585[ms](mean)

Requestspersecond:16.54[#/sec](mean)

表示当前测试的服务器每秒可以处理16.54个静态html的请求事务,后面的mean表示平均。这个数值表示当前机器的整体性能,值越大越好。

Timeperrequest:60443.585[ms](mean)

单个并发的延迟时间,后面的mean表示平均。

隔离开当前并发,单独完成一个请求需要的平均时间。

顺带说一下两个Timeperrequest区别

Timeperrequest:60443.585[ms](mean)

Timeperrequest:60.444[ms](mean,acrossallconcurrentrequests)

前一个衡量单个请求的延迟,cpu是分时间片轮流执行请求的,多并发的情况下,一个并发上的请求时需要等待这么长时间才能得到下一个时间片。

计算方法Timeperrequest:60.444[ms](mean,acrossallconcurrentrequests)*并发数

通俗点说就是当以-c10的并发下完成-n1000个请求的同时,额外加入一个请求,完成这个求平均需要的时间。

后一个衡量性能的标准,它反映了完成一个请求需要的平均时间,在当前的并发情况下,增加一个请求需要的时间。

计算方法Timetakenfortests:60.444seconds/Completerequests:1000

通俗点说就是当以-c10的并发下完成-n1001个请求时,比完成-n1000个请求多花的时间。

你可以适当调节-c和-n大小来测试服务器性能,借助htop指令来直观的查看机器的负载情况。

我的机器是盛大云的超微主机,平时负载cpu是1.7%,htop命令结果截图

加压后的负载100%,负载基本已经上来了。htop命令结果截图

看来我需要好好优化一下,或者就换台机器了。

----------------

ab的参数详细解释

普通的测试,使用-c-n参数配合就可以完成任务

格式:./ab[options][http://]hostname[:port]/path

参数:

-n测试的总请求数。默认时,仅执行一个请求

-c一次并发请求个数。默认是一次一个。

-H添加请求头,例如‘Accept-Encoding:gzip’,以gzip方式请求。

-t测试所进行的最大秒数。其内部隐含值是-n50000。它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。

-p包含了需要POST的数据的文件.

-TPOST数据所使用的Content-type头信息。

-v设置显示信息的详细程度–4或更大值会显示头信息,3或更大值可以显示响应代码(404,200等),2或更大值可以显示警告和其他信息。-V显示版本号并退出。

-w以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。

-i执行HEAD请求,而不是GET。

-C-Ccookie-name=value对请求附加一个Cookie:行。其典型形式是name=value的一个参数对。此参数可以重复。

参考http://go2linux.garron.me/linux//04/how-benchmark-stress-your-apache-nginx-or-iis-server-718

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。