web應用壓力測試

Httperf測試web服務器

最近項目組有一個項目,客戶明確規定使用httperf對我們搭建好的Web服務器進行性能測試,我們頭分給我的任務是熟悉httperf測試工具。google了一番,找到許多有用的資料:
1.使用httperf和autobench直觀的分析服務器能.
2.httperf-and-autobench-in-slax

兩篇文章都提到了httperf以及autobench,我不禁想客戶提出只是httperf,並未提到autobench,這個工具是做什麼的呢?
首先我要先了解httperf,搜索到資料:
httperf是個web 服務器的性能測試工具
Step1)  安裝
cd /usr/local/
tar xvzf httperf-0.9.0.tar.gz
cd httperf-0.9.0
./configure --prefix=/usr/local/weip/httperf-0.9.0
make && make install

Step2) 測試
通過如下命令:
httperf --server xx.com \
        --port 80 \
        --uri /foreground/all_stars \
        --rate 100 \
        --num-conn 2000 \
        --num-call 1 \
        --timeout 5

rate是指每秒多少個請求數,num-conn指共發多少個請求 ,num-call每次連接發送的請求數通常爲1

下面測試條件,我們來試試新浪

httperf --server sina.com.cn --num-conn 300 --rate 30
httperf --client=0/1 --server=sina.com.cn --port=80 --uri=/ --rate=30 --send-buffer=4096 --recv-buffer=16384 --num-conns=300 --num-calls=1
Maximum connect burst length: 1

Total: connections 300 requests 300 replies 300 test-duration 10.687 s

Connection rate: 28.1 conn/s (35.6 ms/conn, <=5 concurrent connections)
Connection time [ms]: min 34.0 avg 98.7 max 4073.1 median 57.5 stddev 314.3
Connection time [ms]: connect 28.9
Connection length [replies/conn]: 1.000

Request rate: 28.1 req/s (35.6 ms/req)
Request size [B]: 64.0

Reply rate [replies/s]: min 29.6 avg 29.7 max 29.8 stddev 0.1 (2 samples)
Reply time [ms]: response 69.8 transfer 0.0
Reply size [B]: header 379.0 content 231.0 footer 0.0 (total 610.0)
Reply status: 1xx=0 2xx=0 3xx=300 4xx=0 5xx=0

CPU time [s]: user 0.31 system 10.32 (user 2.9% system 96.6% total 99.5%)
Net I/O: 18.5 KB/s (0.2*10^6 bps)

Errors: total 0 client-timo 0 socket-timo 0 connrefused 0 connreset 0
Errors: fd-unavail 0 addrunavail 0 ftab-full 0 other 0

每秒迴應最大請求數爲29.7
最大併發數爲5
平均響應時間爲 69.8毫秒

httperf會使用了,可是autobench是什麼工具呢?原來autobench就是一個腳本工具,調用httperf執行autobench腳本,這樣就可以自動進行測試,而不需要自己手動輸測試條件了,接下來在好好研究了autobench一番,原來還可以將測試產生的結果數據轉換爲png圖形格式,很好。

需要安裝如下源碼包:
autobench-2.1.2.tar.gz
gd-2.0.34.tar.bz2
gnuplot-4.2.0.tar.gz
httperf-0.9.0.tar.gz
pcre-7.1.tar.bz2
pcre-devel-4.5-3.2.RHEL4.i386.rpm

安裝前先確認是否安裝過如下程序:

gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel 
libpng-devel libtiff-devel freetype-devel pam-devel pcre pcre-devel


安裝GD2:
cd /usr/local/src
wget http://www.boutell.com/gd/http/gd-2.0.33.tar.gz
tar xzvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure --prefix=/usr/local/gd2
make
make install

echo "//usr/local/gd2/lib" >> /etc/ld.so.conf
ldconfig


安裝texinfo-4.7:
cd /usr/local/src
wget http://ftp.gnu.org/gnu/texinfo/texinfo-4.8.tar.gz
tar zxvf texinfo-4.8.tar.gz
cd texinfo-4.8
./configure
make && make install


安裝gnuplot:
cd /usr/local/src
wget http://nchc.dl.sourceforge.net/sourceforge/gnuplot/gnuplot-4.2.0.tar.gz
tar zxvf gnuplot-4.2.0.tar.gz
cd gnupolt-4.2.0
./configure \
--prefix=/usr/local/gnuplot \
--with-cwdrc --without-row-help \
--with-kpsexpand \
--with-gd=/usr/local/gd2
make && make install


安裝httperf:
cd /usr/local/src
wget ftp://ftp.hpl.hp.com/pub/httperf/httperf-0.8.1.tar.gz 
tar zxvf httperf-0.8.tar.gz 
cd httperf-0.8 
./configure --prefix=/usr/local/httperf
make && make install


安裝autobench包:
cd /usr/local/src
wget http://www.xenoclast.org/autobench/downloads/autobench-2.1.2.tar.gz
tar zxvf autobench-2.1.2.tar.gz 
cd autobench-2.1.2 
make && make install

vi /etc/profile
在HISTSIZE=1000下面添加一行:
export PATH=/usr/local/bin:/usr/local/gnuplot/bin:/usr/local/httperf/bin:$PATH
source /etc/profile
(上面的安裝過程可以不指定路徑,自動安裝,環境變量path就無需手動設置了!)
如果上面編譯都沒有錯誤,執行下面命令:

cp /usr/local/bin/bench2graph /usr/local/bin/bench2png   
vi /usr/local/bin/bench2png

sed -i 's/postscript color/png xffffff/g' /usr/local/bin/bench2png (這句話挺重要,否則生成的png圖片顏色不對!)



測試一個服務器性能,生成tsv文件:

/usr/local/bin/autobench \
--single_host \
--host1=192.168.0.2 \
--port1=80 \
--quiet \
--low_rate=10 \
--high_rate=100 \
--rate_step=10 \
--num_call=1 \
--num_conn=100 \
--timeout=10 \
--file /opt/result.tsv

把tsv文件用圖形表示出來:

/usr/local/bin/bench2png /opt/result.tsv /opt/result.png [ 1 2 3 .... ]

如果對兩臺服務器進行比較,則用下面命令:

/usr/local/bin/autobench \
--host1=squid.yhc.com \
--port1=80 \
--host2=nginx.yhc.com \
--port2=80 \
--quiet \
--low_rate=100 \
--high_rate=5000 \
--rate_step=10 \
--num_call=1 \
--num_conn=3000 \
--timeout=5 \
--file /opt/result.tsv

再把生成的數據轉化成圖形:
/usr/local/bin/bench2png /opt/result.tsv /opt/result.png [ 1 2 3 .... ]


注:
[1 2 3 .... ]的值分別表示如下:

1 dem_req_rate

2   req_rate_nginx.yhc.com
3   con_rate_nginx.yhc.com
4   min_rep_rate_nginx.jackbillow.com
5   avg_rep_rate_nginx.jackbillow.com
6   max_rep_rate_nginx.jackbillow.com
7   stddev_rep_rate_yhc.jackbillow.com
8   resp_time_nginx.jackbillow.com
9   net_io_nginx.jackbillow.com
10 errors_nginx.jackbillow.com
11 req_rate_apache.jackbillow.com
12con_rate_apache.jackbillow.com
13 min_rep_rate_squid.jackbillow.com
14 avg_rep_rate_squid.jackbillow.com
15 max_rep_rate_squid.jackbillow.com
16 stddev_rep_rate_squid.jackbillow.com
17 resp_time_squid.jackbillow.com
18 net_io_squid.jackbillow.com
19 errors_squid.jackbillow.com

例如,我做如下對比:

2   req_rate_nginx.jackbillow.com 
11 req_rate_squid.jackbillow.com
/usr/local/bin/bench2png /opt/result.tsv /opt/result.png [ 2 11 ]


3   con_rate_nginx.jackbillow.com 
12 con_rate_squid.jackbillow.com
/usr/local/bin/bench2png /opt/result.tsv /opt/result.png [ 3 12 ] 
    
4   min_rep_rate_nginx.jackbillow.com 
13 min_rep_rate_squid.jackbillow.com 
/usr/local/bin/bench2png /opt/Result.tsv /opt/result.png [ 4 13 ] 



5   avg_rep_rate_nginx.jackbillow.com  
14 avg_rep_rate_squid.jackbillow.com  
/usr/local/bin/bench2png /opt/resultdef.tsv /opt/resulta5_14.png [ 5 14 ]


6   max_rep_rate_nginx.jackbillow.com 
15 max_rep_rate_squid.jackbillow.com 
/usr/local/bin/bench2png /opt/Resultabc.tsv /opt/resultaabc6_15.png [ 6 15 ]


7   stddev_rep_rate_nginx.jackbillow.com  
16 stddev_rep_rate_squid.jackbillow.com   
/usr/local/bin/bench2png /opt/Resultabc.tsv /opt/resultaabc7_16.png [ 7 16 ]


8   resp_time_nginx.jackbillow.com 
17 resp_time_squid.jackbillow.com  
/usr/local/bin/bench2png /opt/resultdef.tsv /opt/resultaabc8_17.png [ 8 17 ]


9   net_io_nginx.jackbillow.com
18 net_io_squid.jackbillow.com
/usr/local/bin/bench2png /opt/resultdef.tsv /opt/resultaabc9_18.png [ 9 18 ]


10 errors_nginx.jackbillow.com
19 errors_squid.jackbillow.com
/usr/local/bin/bench2png /opt/Resultabc.tsv /opt/resultaabc10_19.png [ 10 19 ]


最後貼張圖片:
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章