自动化测试Web服务器性能 autobench+httperf

    整理这个主要是为学员的项目需要。我希望学员能自行做一个支持GET的简单WEB服务器,能用各种方法优化其下载性能,需要一个能直观了解性能工具以分析程序是否改进。因此 查到资料 autobench+httpref 组合来测试HTTP服务器性能。我只是现在将资料整理一下,按照自己习惯格式边做边整理一下。

 
1.HTTPerf单独使用
 
HP实验室出的命令行HTTP性能测试工具

httpref是通过命令行来调用。它有如下参数

httperf --help
Usage: httperf [-hdvV] [--add-header S] [--burst-length N] [--client N/N]
        [--close-with-reset] [--debug N] [--failure-status N]
        [--help] [--hog] [--http-version S] [--max-connections N]
        [--max-piped-calls N] [--method S] [--no-host-hdr]
        [--num-calls N] [--num-conns N] [--period [d|u|e]T1[,T2]]
        [--port N] [--print-reply [header|body]] [--print-request [header|body]]
        [--rate X] [--recv-buffer N] [--retry-on-failure] [--send-buffer N]
        [--server S] [--server-name S] [--session-cookies]
        [--ssl] [--ssl-ciphers L] [--ssl-no-reuse]
        [--think-timeout X] [--timeout X] [--uri S] [--verbose] [--version]
        [--wlog y|n,file] [--wsess N,N,X] [--wsesslog N,X,file]
        [--wset N,X]

 

其中常用的参数的含义
  • --server S web服务器地址
  • --num-conns N 测试联接数
  • --num-calls N 每连接中发起联接数,一般是1
  • --rate N 每秒请求数
  • --port N 测试端口
  • −−method S 测试HTTP方法,默认为GET
  • --uri S 测试网页,默认为/
  • --timeout N 等待服务器响应时间

测试本地嵌入式Web 服务器 BOA性能.

 httperf --server 127.0.0.1 --port 8080 --num-conns 200 --timeout 5 --uri /index.html

结果:


httperf --timeout=5 --client=0/1 --server=127.0.0.1 --port=8080 --uri=/index.html --send-buffer=4096 --recv-buffer=16384 --num-conns=200 --num-calls=1
Maximum connect burst length: 1

Total: connections 200 requests 200 replies 200 test-duration 2.184 s

Connection rate: 91.6 conn/s (10.9 ms/conn, <=1 concurrent connections)
Connection time [ms]: min 2.8 avg 10.9 max 1301.8 median 4.5 stddev 91.7
Connection time [ms]: connect 0.8
Connection length [replies/conn]: 1.000

Request rate: 91.6 req/s (10.9 ms/req)
Request size [B]: 72.0

Reply rate [replies/s]: min 0.0 avg 0.0 max 0.0 stddev 0.0 (0 samples)
Reply time [ms]: response 2.7 transfer 7.4
Reply size [B]: header 190.0 content 42605.0 footer 0.0 (total 42795.0)
Reply status: 1xx=0 2xx=200 3xx=0 4xx=0 5xx=0

CPU time [s]: user 0.00 system 0.18 (user 0.0% system 8.2% total 8.2%)
Net I/O: 3832.9 KB/s (31.4*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

 


2.HTTPerf+Autobench

每次设置HTTPerf参数来测试实在麻烦,因此autobench就派上用场了。autobench是一个自动测试工具(用的是Perl脚本),用它来调用httperf来测试,省事多了。在他的官网上,也强调与httperf的配合。

  • 主页: http://www.xenoclast.org/autobench
  • 下载:http://www.xenoclast.org/autobench/downloads/autobench-2.1.2.tar.gz
  • 解压 tar xvzf autobench-2.1.2.tar.gz
    • cd cd autobench-2.1.2
  • 编译 make
  • 安装 make install

安装时在我的机器上出现如下错误提示

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en"
    are supported and installed on your system.

这是perl 常见安装问题,我的解决方法是手工设定两个环境变量

export LC_ALL=en_US

export LANGUAGE=en_US

autobench 调用httperf 方法,在其官网给出一些样例了。

2.1单机测试模式

测试单台主机,以下是官网样例 
autobench --single_host --host1 www.test.com --uri1 /10K --quiet     \
          --low_rate 20 --high_rate 200 --rate_step 20 --num_call 10 \
          --num_conn 5000 --timeout 5 --file results.tsv

其参数含义

  • --signle_host 只测单机
  • --host1 测试主机地址
  • --uri1 host1 测试URI
  • --quiet 安静模式
  • --low_rate 测试时最低请求数(指 httperf)
  • --hight_rate 测试时最高请求数
  • --rate_step 每次测试请求数增加步长
  • --num-call 同httperf
  • --num_conn 同httperf
  • --file 测试结果输出的 tsv文件

对boa 的进行自动测试。

autobench --single_host --host1 127.0.0.1 --uri1 /index.html --port1 8080 --quiet --low_rate 20 --high_rate 200 --rate_step 20 --num_call 1 --num_conn 500 --timeout 5 --file results.tsv

tsv文件应该是csv格式的,这是我的BOA测试结果

dem_req_rate    req_rate_127.0.0.1      con_rate_127.0.0.1      min_rep_rate_127.0.0.1  avg_rep_rate_127.0.0.1  max_rep_rate_127.0.0.1  stddev_rep_rate_127.0.0.1       resp_time_127.0.0.1     net_io_127.0.0.1        errors_127.0.0.1
20      20.0    20.0    20.0    20.0    20.0    0.0     15.1    838.8   0
40      39.8    39.8    40.0    40.0    40.0    0.0     25.2    1664.8  0
60      60.1    60.1    54.5    54.5    54.5    0.0     64.6    2515.5  0
80      64.6    64.6    51.6    51.6    51.6    0.0     587.5   2702.5  0
100     71.8    71.8    24.6    24.6    24.6    0.0     919.8   3007.3  0
120     67.4    67.4    23.8    23.8    23.8    0.0     1221.9  2822.0  0
140     68.0    68.0    25.2    25.2    25.2    0.0     1210.9  2845.7  0
160     79.9    79.9    10.8    10.8    10.8    0.0     1485.2  3346.1  0
180     63.1    63.1    1.4     1.4     1.4     0.0     1629.4  2640.4  0
200     67.3    67.3    1.4     1.4     1.4     0.0     2785.8  2810.9  0.200400801603206

2.2 双机测试模式

autobench 还能做两机对比测试,这样可以在同等网络条件下,测试两台服务器性能。它主要用增加几个参数

关掉 --single_host参数,增加 --host2 --uri2 --port2 几个参数即可。

 

3.输出测试图形

tsv格式还是不直观,如果输出图形结果,将更加有直观。autobench建议用gnuplot来输出相应图形.一个科学绘图图形包。

3.1 失败结果(autobech与最新版不兼容)

  • 官网:http://www.gnuplot.info
  • 下载:http://downloads.sourceforge.net/project/gnuplot/gnuplot/4.4.0/gnuplot-4.4.0.tar.gz?use_mirror=nchc
  • 解压 tar xvzf gnuplot-4.4.0.tar.gz
    • cd gnuplot-4.4.0
  • 这个包时间非常新,因此要把系统时间调准点。

 tar: gnuplot-4.4.0/lisp: time stamp 2010-03-14 05:28:45 is 983592 s in the future
tar: gnuplot-4.4.0: time stamp 2010-03-14 05:28:44 is 983591 s in the future

  • 生成Makefile ./configure
  • 编译 make
  • 安装 make install

autobench 使用 bench2graph来生成图形。

执行 bench2graph results.tsv results.png 按网上提示生成bench2png.(直接执行bench2graph 无法生成PNG)

  •   cp /usr/local/bin/bench2graph /usr/local/bin/bench2png
  • sed -i 's/postscript color/png xffffff/g' /usr/local/bin/bench2png

去掉 bench2png 的77行的 echo set data style linespoints >> gnuplot.cmd

因为4.4版本不支持 set data style 选项提示

set data style linespoints
    ^
"gnuplot.cmd", line 6: Unrecognized option.  See 'help set'.


生成输出图形
bench2png results.tsv results.png


 
 
 

3.2 成功的版本

这个图没有曲线?感觉不对换成网上显示成功的gnuplot-4.2.0

  • 解压 tar xvzf gnuplot-4.2.0.tar.gz
  • cd gnuplot-4.2.0
  • 生成Makefile ./configure
  • 编译 make
  • 安装 make install

 

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

sed -i 's/postscript color/png xffffff/g' /usr/local/bin/bench2png

注意这里一定要打开echo set data style linespoints >> gnuplot.cmd

bench2png results.tsv results.png

生成结果

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值