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 ]
最后贴张图片: