paulwong

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

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

              實驗之前我的apache已經安裝了,操作系統: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、現在我們就對51CTO的網站進行一次壓力測試吧,使用命令ab -n1000 -c10 http://www.51cto.com/index.php,其中 -n1000 表示總請求數 -c10表示并發用戶數為10 http://www.51cto.com/index.php 表示請求的URL,下面是測試的結果,其中我們最關心的三個指標,我已經注釋出來了。

           

          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服務器用的是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. /*大家最關心的指標之一,指的是吞吐率
          37. 相當于 LR 中的 每秒事務數 ,后面括號中的 mean 表示這是一個平均值*/  
          38. Requests per second:    13.45 [#/sec] (mean)
          39. /*大家最關心的指標之二,指的是用戶平均請求等待時間
          40. 相當于 LR 中的 平均事務響應時間 ,后面括號中的 mean 表示這是一個平均值*/ 
          41. Time per request:       743.726 [ms] (mean)
          42. /*大家最關心的指標之三,指的是服務器平均請求處理時間
          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、為了使結果更有對比性,我們將并發用戶更改為100個進行壓力測試,我這里只將三個指標貼出來。

          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、將并發用戶改為200個進行測試

          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個并發用戶時的情況

          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)  

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

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

          主站蜘蛛池模板: 大同市| 瑞昌市| 城固县| 慈溪市| 黎川县| 土默特右旗| 建水县| 淮南市| 梓潼县| 宿松县| 东兰县| 同心县| 阳泉市| 铁力市| 唐河县| 威海市| 莎车县| 湄潭县| 柳江县| 青川县| 老河口市| 洛川县| 沙洋县| 桐庐县| 淮北市| 怀来县| 河北区| 西平县| 德清县| 大荔县| 翁源县| 姜堰市| 沙湾县| 平邑县| 陇川县| 本溪| 临沂市| 始兴县| 习水县| 台北市| 邮箱|