qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請訪問 http://qaseven.github.io/

          壓力測試工具apache-ab講解

           最近在做webservices,得到的數(shù)據(jù)是從德國那邊的服務(wù)器。要將這些數(shù)據(jù)整合到現(xiàn)在網(wǎng)站中去。不知道性能如何。就做個壓力測試。現(xiàn)在有些壓力測試工具都是收費的。在開源的apache中自帶個ab工具。就在C:\Apache2. ...
            最近在做webservices,得到的數(shù)據(jù)是從德國那邊的服務(wù)器。要將這些數(shù)據(jù)整合到現(xiàn)在網(wǎng)站中去。不知道性能如何。就做個壓力測試。現(xiàn)在有些壓力測試工具都是收費的。在開源的apache中自帶個ab工具。就在C:\Apache2.2\bin\ab.exe。用它可以檢測自己的程序性能如何。
            用下吧!,可以提高自己代碼質(zhì)量。
            APACHE的bin目錄下。
            格式.ab [options] [http://]hostname[:port]/path
            參數(shù)
          -n requests     Number of requests to perform
          //在測試會話中所執(zhí)行的請求個數(shù)。默認(rèn)時,僅執(zhí)行一個請求
          -c concurrency Number of multiple requests to make
          //一次產(chǎn)生的請求個數(shù)。默認(rèn)是一次一個。
          -t timelimit    Seconds to max. wait for responses
          //測試所進(jìn)行的最大秒數(shù)。其內(nèi)部隱含值是-n 50000。它可以使對服務(wù)器的測試限制在一個固定的總時間以內(nèi)。默認(rèn)時,沒有時間限制。
          -p postfile     File containing data to POST
          //包含了需要POST的數(shù)據(jù)的文件.
          -T content-type Content-type header for POSTing
          //POST數(shù)據(jù)所使用的Content-type頭信息。
          -v verbosity    How much troubleshooting info to print
          //設(shè)置顯示信息的詳細(xì)程度 - 4或更大值會顯示頭信息, 3或更大值可以顯示響應(yīng)代碼(404, 200等), 2或更大值可以顯示警告和其他信息。 -V 顯示版本號并退出。
          -w              Print out results in HTML tables
          //以HTML表的格式輸出結(jié)果。默認(rèn)時,它是白色背景的兩列寬度的一張表。
          -i              Use HEAD instead of GET
          // 執(zhí)行HEAD請求,而不是GET。
          -x attributes   String to insert as table attributes
          //
          -y attributes   String to insert as tr attributes
          //
          -z attributes   String to insert as td or th attributes
          //
          -C attribute    Add cookie, eg. ‘Apache=1234. (repeatable)
          //-C cookie-name=value 對請求附加一個Cookie:行。 其典型形式是name=value的一個參數(shù)對。此參數(shù)可以重復(fù)。
          -H attribute    Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’
          Inserted after all normal header lines. (repeatable)
          -A attribute    Add Basic WWW Authentication, the attributes
          are a colon separated username and password.
          -P attribute    Add Basic Proxy Authentication, the attributes
          are a colon separated username and password.
          //-P proxy-auth-username:password 對一個中轉(zhuǎn)代理提供BASIC認(rèn)證信任。用戶名和密碼由一個:隔開,并以base64編碼形式發(fā)送。無論服務(wù)器是否需要(即, 是否發(fā)送了401認(rèn)證需求代碼),此字符串都會被發(fā)送。
          -X proxy:port   Proxyserver and port number to use
          -V              Print version number and exit
          -k              Use HTTP KeepAlive feature
          -d              Do not show percentiles served table.
          -S              Do not show confidence estimators and warnings.
          -g filename     Output collected data to gnuplot format file.
          -e filename     Output CSV file with percentages served
          -h              Display usage information (this message)
            //-attributes 設(shè)置 屬性的字符串. 缺陷程序中有各種靜態(tài)聲明的固定長度的緩沖區(qū)。另外,對命令行參數(shù)、服務(wù)器的響應(yīng)頭和其他外部輸入的解析也很簡單,這可能會有不良后果。它沒有完整地實現(xiàn) HTTP/1.x; 僅接受某些’預(yù)想’的響應(yīng)格式。 strstr(3)的頻繁使用可能會帶來性能問題,即, 你可能是在測試ab而不是服務(wù)器的性能。

           參數(shù)很多,一般我們用 -c 和 -n 參數(shù)就可以了. 例如:
            打開cmd,輸入 以下代碼。
            cd C:\Apache2.2\bin
            ab -n 1000 -c 100 http://zf.guqin.com/index/index
            這個表示同時處理100個請求并運行1000次index.php文件。以下是打印出來的內(nèi)容。
          This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0
          Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
          Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
          Benchmarking 127.0.0.1 (be patient)
          Completed 100 requests
          Completed 200 requests
          Completed 300 requests
          Completed 400 requests
          Completed 500 requests
          Completed 600 requests
          Completed 700 requests
          Completed 800 requests
          Completed 900 requests
          Finished 1000 requests
          Server Software:        Apache/2.2.8
          //平臺apache 版本2.2.8
          Server Hostname:        zf.guqin.com
          //服務(wù)器主機名
          Server Port:            80
          //服務(wù)器端口
          Document Path:          /index.php
          //測試的頁面文檔
          Document Length:        1018 bytes
          //文檔大小
          Concurrency Level:      1000
          //并發(fā)數(shù)
          Time taken for tests:   8.188731 seconds
          //整個測試持續(xù)的時間
          Complete requests:      1000
          //完成的請求數(shù)量
          Failed requests:        0
          //失敗的請求數(shù)量
          Write errors:           0
          Total transferred:      1361581 bytes
          //整個場景中的網(wǎng)絡(luò)傳輸量
          HTML transferred:       1055666 bytes
          //整個場景中的HTML內(nèi)容傳輸量
          Requests per second:    122.12 [#/sec] (mean)
          //大家最關(guān)心的指標(biāo)之一,相當(dāng)于 LR中的每秒事務(wù)數(shù),后面括號中的 mean表示這是一個平均值
          Time per request:       8188.731 [ms] (mean)
          //大家最關(guān)心的指標(biāo)之二,相當(dāng)于 LR中的平均事務(wù)響應(yīng)時間,后面括號中的 mean表示這是一個平均值
          Time per request:       8.189 [ms] (mean, across all concurrent requests)
          //每個請求實際運行時間的平均值
          Transfer rate:          162.30 [Kbytes/sec] received
          //平均每秒網(wǎng)絡(luò)上的流量,可以幫助排除是否存在網(wǎng)絡(luò)流量過大導(dǎo)致響應(yīng)時間延長的問題
          Connection Times (ms)
          min mean[+/-sd] median   max
          Connect:        4 646 1078.7     89    3291
          Processing:   165 992 493.1    938    4712
          Waiting:      118 934 480.6    882    4554
          Total:        813 1638 1338.9   1093    7785
          //網(wǎng)絡(luò)上消耗的時間的分解,各項數(shù)據(jù)的具體算法還不是很清楚
          Percentage of the requests served within a certain time (ms)
          50%   1093
          66%   1247
          75%   1373
          80%   1493
          90%   4061
          95%   4398
          98%   5608
          99%   7368
          100%   7785 (longest request)
            //整個場景中所有請求的響應(yīng)情況。在場景中每個請求都有一個響應(yīng)時間,其中50%的用戶響應(yīng)時間小于1093 毫秒,60% 的用戶響應(yīng)時間小于1247 毫秒,最大的響應(yīng)時間小于7785 毫秒
            由于對于并發(fā)請求,cpu實際上并不是同時處理的,而是按照每個請求獲得的時間片逐個輪轉(zhuǎn)處理的,所以基本上第一個Time per request時間約等于第二個Time per request時間乘以并發(fā)請求數(shù)。
            window下面測試 p參數(shù)的使用
            ab.exe -n 100 -c 10  -p "D:/post.txt" -T "application/x-www-form-urlencoded" "http://localhost/test/index.php"
            post.txt文件內(nèi)容
            myname=xiaoming&sex=1&age=10
            index.php內(nèi)容
            <?php
            file_put_contents('request.txt',implode('####',$_REQUEST));
            測試結(jié)果
            request.txt文件內(nèi)容  提示 request.txt和index.php同目錄
            xiaoming####1####10
            window下面測試 A參數(shù)的使用
            ab.exe -A myname:mypassword -n 100 -c 10   "http://localhost/test/index.php"
            PHP認(rèn)證學(xué)習(xí)地址
            http://www.php100.com/manual/php/features.http-auth.html
            index.php內(nèi)容
          <?php
          if (!isset($_SERVER['PHP_AUTH_USER'])) {
          header('WWW-Authenticate: Basic realm="My Realm"');
          header('HTTP/1.0 401 Unauthorized');
          echo 'Text to send if user hits Cancel button';
          exit;
          } else {
          $str = "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
          $str .="<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
          file_put_contents('request.txt',$str);
          }
            request.txt測試結(jié)果 提示和index.php一個文件
            <p>Hello myname.</p><p>You entered mypassword as your password.</p>

          posted on 2014-01-22 10:12 順其自然EVO 閱讀(390) 評論(0)  編輯  收藏 所屬分類: web 前端性能測試

          <2014年1月>
          2930311234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 会宁县| 叶城县| 特克斯县| 琼海市| 柞水县| 北碚区| 万全县| 竹山县| 池州市| 忻城县| 遵义县| 大宁县| 炉霍县| 吉木萨尔县| 威信县| 安丘市| 建湖县| 辽中县| 庆安县| 鲜城| 屯门区| 忻城县| 绍兴市| 邯郸县| 香河县| 丁青县| 西林县| 即墨市| 汽车| 镇雄县| 高淳县| 简阳市| 藁城市| 涟源市| 漾濞| 方山县| 永修县| 五华县| 布拖县| 清镇市| 德阳市|