zoukankan      html  css  js  c++  java
  • 使用Apache Server 的ab进行web请求压力测试

    参考:http://www.cnblogs.com/spring3mvc/archive/2010/11/23/2414741.html

    自己写代码经常是顺着逻辑写下去,写完后run一下,ok就玩完事了。直到遇到一个又一个的问题的时候才回头过来重新修改。这就是没有测试的悲剧。因此,在今后的代码中一定要尝试着去写测试,去做测试。

    发现Apache Server下有个工具ab可以进行并发请求,正好有个需求想要知道并发下的访问情况。

    1.下载

    访问:http://httpd.apache.org/download.cgi

    然后点击:

    然后跳到一个页面说只提供源码,自己编译,云彩。不过也提供了推荐第三方编译,选择第一个:

    然后是选择镜像和版本,不要选择德国的:

    2.安装

    我这是买椟还珠的游戏,不想去了解Apache的功能,只想要ab。所以直接解压,然后在bin目录找到ab就可以了:

    3.测试

    输入ab就可以看到帮助文档

    D:Javahttpd-2.4.23-x64-vc14Apache24in>ab
    ab: wrong number of arguments
    Usage: ab [options] [http://]hostname[:port]/path
    Options are:
        -n requests     Number of requests to perform
        -c concurrency  Number of multiple requests to make at a time
        -t timelimit    Seconds to max. to spend on benchmarking
                        This implies -n 50000
        -s timeout      Seconds to max. wait for each response
                        Default is 30 seconds
        -b windowsize   Size of TCP send/receive buffer, in bytes
        -B address      Address to bind to when making outgoing connections
        -p postfile     File containing data to POST. Remember also to set -T
        -u putfile      File containing data to PUT. Remember also to set -T
        -T content-type Content-type header to use for POST/PUT data, eg.
                        'application/x-www-form-urlencoded'
                        Default is 'text/plain'
        -v verbosity    How much troubleshooting info to print
        -w              Print out results in HTML tables
        -i              Use HEAD instead of GET
        -x attributes   String to insert as table attributes
        -y attributes   String to insert as tr attributes
        -z attributes   String to insert as td or th attributes
        -C attribute    Add cookie, eg. 'Apache=1234'. (repeatable)
        -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
                        Inserted after all normal header lines. (repeatable)
        -A attribute    Add Basic WWW Authentication, the attributes
                        are a colon separated username and password.
        -P attribute    Add Basic Proxy Authentication, the attributes
                        are a colon separated username and password.
        -X proxy:port   Proxyserver and port number to use
        -V              Print version number and exit
        -k              Use HTTP KeepAlive feature
        -d              Do not show percentiles served table.
        -S              Do not show confidence estimators and warnings.
        -q              Do not show progress when doing more than 150 requests
        -l              Accept variable document length (use this for dynamic pages)
        -g filename     Output collected data to gnuplot format file.
        -e filename     Output CSV file with percentages served
        -r              Don't exit on socket receive errors.
        -m method       Method name
        -h              Display usage information (this message)
    
    D:Javahttpd-2.4.23-x64-vc14Apache24in>
    View Code

    举例:

    D:Javahttpd-2.4.23-x64-vc14Apache24in>ab -n 20 -c 10 localhost:8080/user/all

    -n表示一共请求20次

    -c表示并发量为10次。

    也就是说,会进行两个并发,每次10个。

  • 相关阅读:
    javascript动态创建Option选项
    Javascript中最常用的25个经典技巧
    C#常用函数和方法集
    C#邮件发送程序
    CSS菜单
    笔记本将有线变无线网
    svn有权限但是不能提交的原因
    IE6在https下认为iframe和about:blank不安全
    VS2008创建MFC项目提示无法找到userimages.bmp
    往数据库中插入流数据的问题
  • 原文地址:https://www.cnblogs.com/woshimrf/p/5678348.html
Copyright © 2011-2022 走看看