Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1644309
  • 博文数量: 311
  • 博客积分: 7778
  • 博客等级: 少将
  • 技术积分: 4186
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-09 19:59
个人简介

蓝点工坊(http://www.bluedrum.cn) 创始人,App和嵌入式产品开发。同时也做相应培训和外包工作。 详细介绍 http://pan.baidu.com/s/1y2g88

文章存档

2012年(3)

2011年(115)

2010年(170)

2009年(23)

分类: 系统运维

2010-03-29 23:49:22

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

 
1.HTTPerf单独使用
 
HP实验室出的命令行HTTP性能测试工具
  • 主页:  
  • 下载:
  • 解压:
    •    tar xvzf httperf-0.9.0.tar.gz
    •    cd httperf-0.9.0
  • 生成Makefile
    •  ./configure
  • 编译 make
  • 安装 make install

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的配合。

  • 主页:
  • 下载:
  • 解压 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 --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与最新版不兼容)

  • 官网:gnuplot.info
  • 下载:
  • 解压 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

生成结果

 




 

 

  
 
阅读(5886) | 评论(3) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-12-02 17:28:37

为了节省大家的时间, 请去官网看文档。 http://www.xenoclast.org/autobench/

chinaunix网友2010-12-02 17:26:34

无语了,大哥你 man bench2graph 行不, 浪费我半天时间 bench2graph(1) bench2graph(1) NAME bench2graph - draws Postscript graphs from Autobench output (using gnuplot) SYNOPSIS bench2graph file outfile [col1 col2 col3...] DESCRIPTION bench2graph takes a TSV format autobench results file, and uses gnuplot to graph the results, producing output in Postscript.

chinaunix网友2010-05-01 00:16:32

好,写得不错