paulwong

          Apache自帶的壓力測試工具——ab初體驗

            我們知道壓力測試的軟件確實很多,諸如微軟的WAST,惠普的LoadRunner以及等等其他的,但這些軟件學(xué)習(xí)起來還是需要花費些時間,在選擇上實在頭痛,后來在郭欣的那本《構(gòu)建高性能WEB站點》上看到了他介紹的這款A(yù)pache自帶的壓力測試工具ab,十分喜愛,于是今天終于有機會體驗下ab對網(wǎng)站的壓力測試。

              實驗之前我的apache已經(jīng)安裝了,操作系統(tǒng):Ubuntu 10.04 VMware 7.0

          1、先查看一下版本信息 ab -V(注意是大寫的V)

          1. studiogang@studiogang:~$ ab -V  
          2. This is ApacheBench, Version 2.3 <$Revision: 655654 $>  
          3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/  
          4. Licensed to The Apache Software Foundation, http://www.apache.org/  

           2、我們也可以使用小寫的v查看下ab命令的一些屬性 ab -v

          1. studiogang@studiogang:~$ ab -v  
          2. ab: option requires an argument -- v  
          3. ab: wrong number of arguments  
          4. Usage: ab [options] [http[s]://]hostname[:port]/path  
          5. Options are:  
          6.     -n requests     Number of requests to perform  
          7.     -c concurrency  Number of multiple requests to make  
          8.     -t timelimit    Seconds to max. wait for responses  
          9.     -b windowsize   Size of TCP send/receive buffer, in bytes  
          10.     -p postfile     File containing data to POST. Remember also to set -T  
          11.     -u putfile      File containing data to PUT. Remember also to set -T  
          12.     -T content-type Content-type header for POSTing, eg.  
          13.                     'application/x-www-form-urlencoded'  
          14.                     Default is 'text/plain'  
          15.     -v verbosity    How much troubleshooting info to print  
          16.     -w              Print out results in HTML tables  
          17.     -i              Use HEAD instead of GET  
          18.     -x attributes   String to insert as table attributes  
          19.     -y attributes   String to insert as tr attributes  
          20.     -z attributes   String to insert as td or th attributes  
          21.     -C attribute    Add cookie, eg. 'Apache=1234. (repeatable)  
          22.     -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'  
          23.                     Inserted after all normal header lines. (repeatable)  
          24.     -A attribute    Add Basic WWW Authentication, the attributes  
          25.                     are a colon separated username and password.  
          26.     -P attribute    Add Basic Proxy Authentication, the attributes  
          27.                     are a colon separated username and password.  
          28.     -X proxy:port   Proxyserver and port number to use  
          29.     -V              Print version number and exit  
          30.     -k              Use HTTP KeepAlive feature  
          31.     -d              Do not show percentiles served table.  
          32.     -S              Do not show confidence estimators and warnings.  
          33.     -g filename     Output collected data to gnuplot format file.  
          34.     -e filename     Output CSV file with percentages served  
          35.     -r              Don't exit on socket receive errors.  
          36.     -h              Display usage information (this message)  
          37.     -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)  
          38.     -f protocol     Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)  

          3、現(xiàn)在我們就對51CTO的網(wǎng)站進(jìn)行一次壓力測試吧,使用命令ab -n1000 -c10 http://www.51cto.com/index.php,其中 -n1000 表示總請求數(shù) -c10表示并發(fā)用戶數(shù)為10 http://www.51cto.com/index.php 表示請求的URL,下面是測試的結(jié)果,其中我們最關(guān)心的三個指標(biāo),我已經(jīng)注釋出來了。

           

          1. studiogang@studiogang:~$ ab -n1000 -c10 http://www.51cto.com/index.php  
          2. This is ApacheBench, Version 2.3 <$Revision: 655654 $>  
          3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/  
          4. Licensed to The Apache Software Foundation, http://www.apache.org/  
          5.  
          6.  
          7. Benchmarking www.51cto.com (be patient)  
          8. Completed 100 requests  
          9. Completed 200 requests  
          10. Completed 300 requests  
          11. Completed 400 requests  
          12. Completed 500 requests  
          13. Completed 600 requests  
          14. Completed 700 requests  
          15. Completed 800 requests  
          16. Completed 900 requests  
          17. Completed 1000 requests  
          18. Finished 1000 requests  
          19.  
          20.  /*WEB服務(wù)器用的是nginx*/
          21. Server Software:        nginx  
          22. Server Hostname:        www.51cto.com  
          23. Server Port:            80 
          24.  
          25. Document Path:          /index.php  
          26. Document Length:        154 bytes  
          27.  
          28. Concurrency Level:      10 
          29. Time taken for tests:   74.373 seconds  
          30. Complete requests:      1000 
          31. Failed requests:        0 
          32. Write errors:           0 
          33. Non-2xx responses:      1000 
          34. Total transferred:      330000 bytes  
          35. HTML transferred:       154000 bytes
          36. /*大家最關(guān)心的指標(biāo)之一,指的是吞吐率
          37. 相當(dāng)于 LR 中的 每秒事務(wù)數(shù) ,后面括號中的 mean 表示這是一個平均值*/  
          38. Requests per second:    13.45 [#/sec] (mean)
          39. /*大家最關(guān)心的指標(biāo)之二,指的是用戶平均請求等待時間
          40. 相當(dāng)于 LR 中的 平均事務(wù)響應(yīng)時間 ,后面括號中的 mean 表示這是一個平均值*/ 
          41. Time per request:       743.726 [ms] (mean)
          42. /*大家最關(guān)心的指標(biāo)之三,指的是服務(wù)器平均請求處理時間
          43. Time per request:       74.373 [ms] (mean, across all concurrent requests)  
          44. Transfer rate:          4.33 [Kbytes/sec] received  
          45.  
          46. Connection Times (ms)  
          47.               min  mean[+/-sd] median   max  
          48. Connect:      129  163 245.3    145    3154 
          49. Processing:   129  576 1510.8    147   11756 
          50. Waiting:      129  567 1502.0    147   11756 
          51. Total:        261  739 1543.7    294   11888 
          52.  
          53. Percentage of the requests served within a certain time (ms)  
          54.   50%    294 
          55.   66%    297 
          56.   75%    304 
          57.   80%    308 
          58.   90%   1290 
          59.   95%   3452 
          60.   98%   7582 
          61.   99%   7962 
          62.  100%  11888 (longest request)  

          4、為了使結(jié)果更有對比性,我們將并發(fā)用戶更改為100個進(jìn)行壓力測試,我這里只將三個指標(biāo)貼出來。

          1. Requests per second:    190.95 [#/sec] (mean)  
          2. Time per request:       523.694 [ms] (mean)  
          3. Time per request:       5.237 [ms] (mean, across all concurrent requests)  

          5、將并發(fā)用戶改為200個進(jìn)行測試

          1. Requests per second:    186.00 [#/sec] (mean)  
          2. Time per request:       1149.433 [ms] (mean)  
          3. Time per request:       5.747 [ms] (mean, across all concurrent requests)  

          6、500個并發(fā)用戶時的情況

          1. Requests per second:    180.99 [#/sec] (mean)  
          2. Time per request:       2631.662 [ms] (mean)  
          3. Time per request:       5.263 [ms] (mean, across all concurrent requests)  

               我們來分析下測試的結(jié)果,先對比下吞吐率,當(dāng)并發(fā)用戶的時候吞吐率最高為190 reqs/s,當(dāng)并發(fā)用戶數(shù)為200,500 吞吐率下降了,隨之用戶的等待時間更是明顯增加了,已經(jīng)有2s的等待時間了。這說明性能明顯下降了。當(dāng)然分析這個測試結(jié)果并不是說明51CTO的網(wǎng)站的并發(fā)用戶只能在500左右,因為我是在服務(wù)器負(fù)荷的情況下就行測試的,這顯然不能說明問題。另外我們在生產(chǎn)環(huán)境下測試的時候,最好能將測試結(jié)果做成報表,這樣可以非常清晰地對比出問題來,好了,我該準(zhǔn)備下,給上面提交一份我們公司網(wǎng)站的測試報告了。

          posted on 2015-01-08 19:02 paulwong 閱讀(1178) 評論(0)  編輯  收藏 所屬分類: 性能優(yōu)化

          主站蜘蛛池模板: 西贡区| 霍邱县| 潜山县| 岳西县| 贵定县| 大关县| 华容县| 长乐市| 马龙县| 永登县| 乌拉特前旗| 余姚市| 九龙县| 志丹县| 西和县| 红河县| 浪卡子县| 连山| 阜康市| 旬邑县| 高唐县| 东安县| 漠河县| 区。| 永顺县| 常州市| 布拖县| 平湖市| 毕节市| 连云港市| 盐山县| 南岸区| 晋江市| 石门县| 平谷区| 德安县| 胶州市| 奉新县| 凤山县| 连平县| 茶陵县|