pacheBench測試性能并使用GnuPlot繪制圖表
關于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 閱讀(387) 評論(0) 編輯 收藏 所屬分類: 性能測試