Chinaunix首页 | 论坛 | 博客
  • 博客访问: 26187808
  • 博文数量: 2065
  • 博客积分: 10377
  • 博客等级: 上将
  • 技术积分: 21525
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-04 17:50
文章分类

全部博文(2065)

文章存档

2012年(2)

2011年(19)

2010年(1160)

2009年(969)

2008年(153)

分类: 系统运维

2010-07-24 11:33:40

apache中的ab压力测试工具

时间:2010-7-24

1.介绍

 Ab工具是专门用于以HTTPSERVER的压力测试,可以同时模拟多个并发请求。

2.选项介绍

Usage: ab [options] [http://]hostname[:port]/path

Options are:

    -n requests     Number of requests to perform

    -c concurrency  Number of multiple requests to make

    -t timelimit    Seconds to max. wait for responses

    -b windowsize   Size of TCP send/receive buffer, in bytes

    -p postfile     File containing data to POST. Remember also to set -T

    -T content-type Content-type header for POSTing, 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.

    -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.

    -h              Display usage information (this message)

中文

1、使用语法 ab [options] [http://]hostname[:port]/path

注意:要带上URI的否则就提示错误的URL

2、选项介绍

-n requests     Number of requests to perform请求个数默认是1

-c concurrency  一次产生的请求个数默认是一次一个

-t timelimit     测试所进行的最大秒数(你不可能一直在测试即最大时间值)默认无限制

-b windowsize   Size of TCP send/receive buffer, in bytes

-p postfile     File containing data to POST. Remember also to set –T 模拟POST的时候有用

-T content-type Content-type header for POSTing, eg.

                    'application/x-www-form-urlencoded'

                    Default is 'text/plain'

表示POST数据的时候所需要的content-type头信息

-v verbosity    How much troubleshooting info to print 设置显示信息的详细程序-v 4或更大会显示头信息 3或更大值可以显示响应代码(404200等)2或更大可以显示警告和其他信息-V能够显示版本号并退出。

-w              Print out results in HTML tables HTML表格的格式输出结果

-i              Use HEAD instead of GETHEAD代替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)添加COOKIE行格式为name=value

-H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'

                    Inserted after all normal header lines. (repeatable)

添加请求HTTP请求头部信息

-A attribute    Add Basic WWW Authentication, the attributes

                    are a colon separated username and password.

添加WWWHTTP认证这个功能其实我们是用得比较少的。

-X proxy:port   Proxyserver and port number to use

对中转代理提供BASIC认证信任。其中用户名与密码由一个:隔开,并以base64编码形式发送。

-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.

    -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.

    -h              Display usage information (this message)

一般我们可以使用-c –n就行

示例

ab -n 500 -c 100 -w   > a.html 生成报表

因为我需要有报表所以加上-w

这个表示我们每一次是开启了100个并发线程。一共发起了500次请求。这样算下来的话就是一个线程去请求5次。

打印结果

Server Software:

Microsoft-IIS/6.0

Server Hostname:

Server Port:

80

Document Path:

/index.asp

Document Length:

197 bytes

Concurrency Level:

100

Time taken for tests:

36.172 seconds /*整个测试持续的时间*/

Complete requests:

500 /*完成的请求数量*/

Failed requests:

1 /*失败的请求数量*/

(Connect: 1, Length: 0, Exceptions: 0)

Total transferred:

229500 bytes /*整个场景中的网络传输量*/

HTML transferred:

98500 bytes /*整个场景中的HTML内容传输量*/

Requests per second:

13822.89 /*大家最关心的指标之一,相当于 LR 中的 每秒事务数 ,后面括号中的 mean 表示这是一个平均值*/

Transfer rate:

6344.71 kb/s received /*平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题*/

Connnection Times (ms) /*网络上消耗的时间的分解,各项数据的具体算法还不是很清楚*/

 

min

avg

max

Connect:

16

30

47

Processing:

62

6882

24047

Total:

78

6912

24094

 

/*大家最关心的指标之二,相当于 LR 中的 平均事务响应时间 ,后面括号中的 mean 表示这是一个平均值*/

Time per request:       3234.651 [ms] (mean)

 

 

 

遇到的一个并发数问题

abapache benchmark)的并发数限制

使用ab的时候当并发数超过1024就会示出错:
windows
下提示:apr_pollset_create failed: Invalid argument (22)
linux
下提示:socket: Too many open files (24)

下面是从CSDN转的一篇linux下的解决办法
=======================================
ab
测试apache出错的解决办法 http://blog.csdn.net/answerzy/archive/2007/11/19/1892194.aspx
[root@answer bin]# ./ab -n 20000 -c 2000
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd,
Copyright 1997-2005 The Apache Software Foundation,

Benchmarking 192.168.2.60 (be patient)
socket: Too many open files (24)

解决办法: bash自带的ulimit, 各大版本均有提供
ulimit -n 2000(
你需要的值)
=======================================
这应该不难理解,linux是通过文件来对设备进行管理,ulimit -n是设置同时打开文件的最大数值,ab中每一个连接打开一个设备文件,所以设置这个值就可以解决了。未发现有windows下的解决办法,尝试过按网上 一些文章更改tcpip的并发连接数也不行,如果那位知道,不妨告知一下。

 

与进程最大打开的文件数相关的。


问题  如何在WIN平台解决这个1024的魔咒????

 

 

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