qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          pacheBench測試性能并使用GnuPlot繪制圖表

           Apache Bench 是web性能測試工具,功能強大。但輸出的結果只是數字形式,不容易看到數據的變化。因此,GnuPlot的強大繪制功能正好可以彌補Apache Bench這方面的不足。
            關于ApacheBench的安裝與使用可以參考我之前寫的《ubuntu中安裝apache ab命令進行簡單壓力測試
            GnuPlot 下載地址:http://www.gnuplot.info/download.html
            GnuPlot 文檔地址:http://www.gnuplot.info/documentation.html
            GnuPlot的安裝:
          tar zxvf gnuplot-4.6.4.tar.gz
          cd gnuplot-4.6.4
          ./configure
          sudo make && sudo make install
            GnuPlot的使用:
            首先,使用ApacheBench 測試性能,并將測試結果寫入文件,我們分別對http://localhost/index.php 進行三次性能測試。
          ab -n 500 -c 100 -g ./ab_500_100.dat http://localhost/index.php
          ab -n 500 -c 200 -g ./ab_500_200.dat  http://localhost/index.php
          ab -n 500 -c 300 -g ./ab_500_300.dat  http://localhost/index.php
            參數-g 表示將測試結果導出為一個gnuplot文件 ,三次測試的結果會保存在 ab_500_100.dat,ab_500_200.dat,ab_500_300.dat中。
            gnuplot文件內容格式如下:
          starttime   seconds ctime   dtime   ttime   wait
          Mon Jan 27 21:03:02 2014    1390827782  89  503 592 28
          Mon Jan 27 21:03:02 2014    1390827782  84  591 676 24
          Mon Jan 27 21:03:02 2014    1390827782  93  616 710 24
          Mon Jan 27 21:03:02 2014    1390827782  94  628 722 28
          Mon Jan 27 21:03:02 2014    1390827782  84  741 824 26
          Mon Jan 27 21:03:02 2014    1390827782  84  741 825 26
          Mon Jan 27 21:03:02 2014    1390827782  101 725 826 23
          Mon Jan 27 21:03:02 2014    1390827782  124 707 831 80
          Mon Jan 27 21:03:02 2014    1390827782  204 629 833 28
          Mon Jan 27 21:03:02 2014    1390827782  95  741 836 26
          Mon Jan 27 21:03:02 2014    1390827782  96  743 838 50
          Mon Jan 27 21:03:02 2014    1390827782  96  744 840 40
          Mon Jan 27 21:03:02 2014    1390827782  109 773 883 36
          Mon Jan 27 21:03:02 2014    1390827782  109 774 883 37
          Mon Jan 27 21:03:02 2014    1390827782  153 765 918 51
          Mon Jan 27 21:03:02 2014    1390827782  141 778 919 76
          Mon Jan 27 21:03:02 2014    1390827782  115 814 929 28
          Mon Jan 27 21:03:02 2014    1390827782  103 831 934 23
          Mon Jan 27 21:03:02 2014    1390827782  103 831 934 23
          Mon Jan 27 21:03:02 2014    1390827782  108 831 939 36
          Mon Jan 27 21:03:02 2014    1390827782  115 825 940 64
          Mon Jan 27 21:03:02 2014    1390827782  162 783 945 87
          Mon Jan 27 21:03:02 2014    1390827782  119 831 950 32
          Mon Jan 27 21:03:02 2014    1390827782  108 844 952 15
          Mon Jan 27 21:03:02 2014    1390827782  128 830 958 32
          Mon Jan 27 21:03:02 2014    1390827782  128 831 958 35
          Mon Jan 27 21:03:02 2014    1390827782  108 856 964 87
          Mon Jan 27 21:03:02 2014    1390827782  123 843 967 15
            后面省略。。 然后,根據導出的gnuplot文件繪制圖表,繪制腳本如下:
          # 設定輸出圖片的格式
          set terminal png
          # 設定輸出的圖片文件名
          set output "ab_500.png"
          # 圖表的標題
          set title "ab_500 ab -n 500 -c 100,200,300"
          # 設定圖表的X軸和Y軸縮放比例(相當于調整圖片的縱橫比例,方形的不好看啊)
          set size 1,0.7
          # 設定以Y軸數據為基準繪制柵格(就是示例圖表中的橫向虛線)
          set grid y
          # X軸標題
          set xlabel "request"
          # Y軸標題
          set ylabel "response time (ms)"
          # 設定plot的數據文件,曲線風格和圖例名稱,以第九列數據ttime為基準數據繪圖
          plot "ab_500_100.dat" using 9 smooth sbezier with lines title "conc per 100","ab_500_200.dat" using 9 smooth sbezier with lines title "conc per 200","ab_500_300.dat" using 9 smooth sbezier with lines title "conc per 300"
            參數說明:
            set size 1,0.7 縮放比例,前面是X軸,后面是Y軸, (0, 1]的一個浮點數,1為原始值
            using 9 表示用哪一列數據繪圖,數字是數據行按照空格或制表符分割的字段數字索引,從1開始
            smooth sbezier plot提供的一些數據填充算法以保證線條平滑度的,包含如下選項:smooth {unique | csplines | acsplines | bezier | sbezier},更詳細解釋請參考官方文檔
            with lines title "xxx" 這個會再右上角生成一個圖例,用于區分什么顏色的線條是哪一項數據
            生成的圖表如下:

          posted on 2014-01-30 12:00 順其自然EVO 閱讀(386) 評論(0)  編輯  收藏 所屬分類: 性能測試

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

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 南澳县| 油尖旺区| 福清市| 湛江市| 韶关市| 镇赉县| 尼木县| 武邑县| 轮台县| 临沭县| 出国| 历史| 彰化县| 永仁县| 广南县| 炎陵县| 赣榆县| 武义县| 辽中县| 班戈县| 邵阳市| 化德县| 弥勒县| 古田县| 林西县| 沙雅县| 九寨沟县| 宾川县| 衢州市| 南澳县| 兴隆县| 兖州市| 祁连县| 锡林浩特市| 新余市| 德安县| 会东县| 酒泉市| 阿荣旗| 沛县| 农安县|