您的位置:首页 > 运维架构 > 网站架构

网站压力测试(压测)

2016-01-18 17:13 711 查看
ab的全称是Apache Bench,Apache附带的ab命令非常容易使用,可以直接在Web服务器本地发起测试请求。ab进行一切测试的本质都是基于HTTP的,所以可以说ab对于Web服务器软件的黑盒性能测试,获得的一切数据和计算结果,都是可以通过HTTP来解释的;

ab.exe是apache自带的一款压力测试工具,安装完apache后就有了

基本用法:

进入到cmd 控制台

ab.exe –n 访问的总次数 –c 有多少人访问(并发量) 访问的页面url

举例说明:

ab.exe –n 1000 –c 100 http://locahost/1230test/newfile.php



参数说明:(加粗的比较重要) * 后面括号中的 mean 表示这是一个平均值

Server Software:        web服务器软件及版本
Server Hostname:        请求的地址
Server Port:            请求的端口

Document Path:          请求的页面路径
Document Length:        页面大小

Concurrency Level:      并发数
Time taken for tests:   测试总共花费的时间
Complete requests:      完成的请求数
Failed requests:        失败的请求数
Write errors:           写入错误
Total transferred:      总共传输字节数,包含http的头信息等
HTML transferred:       html字节数,实际的页面传递字节数
Requests per second:    每秒处理的请求数,服务器的吞吐量(重要)
Time per request:       平均数,用户平均请求等待时间  即100个人同时请求1次花费的时间
Time per request:       服务器平均处理时间  即一个人完成一次请求需要的时间
Transfer rate:          平均传输速率(每秒收到的速率)

在测试过程中会出现以下这些错误
1)ab并发数不能大于请求数,会提示
ab: Cannot use concurrency level greater than total number of requests

2)请求数默认不能超过1024个,会提示
socket: Too many open files (24)
可用ulimit -n命令修改,例如:ulimit -n 8192 (设置用户可以同时打开的最大文件数)。

3)并发数默认不能大于20000个,会提示
ab: Invalid Concurrency [Range 0..20000]
需要修改apache源代码support目录下ab.c文件,找到:
#define MAX_CONCURRENCY 20000
将宏定义的值改大,重新编译安装apache。

4)提示
apr_socket_recv: Connection reset by peer (104)
网上说是apr-util有些问题,不太稳定,多试几次就好了。

附:其他命令说明:


//在测试会话中所执行的请求个数。默认时,仅执行一个请求

-n requests Number of requests to perform




//一次产生的请求个数。默认是一次一个。

-c concurrency Number of multiple requests to make

//测试所进行的最大秒数。其内部隐含值是-n 50000。它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。

-t timelimit Seconds to max. wait for responses




//包含了需要POST的数据的文件.

-p postfile File containing data to POST

//POST数据所使用的Content-type头信息。

-T content-type Content-type header for POSTing

//设置显示信息的详细程度 - 4或更大值会显示头信息, 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。 -V 显示版本号并退出。

-v verbosity How much troubleshooting info to print

//以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。

-w Print out results in HTML tables

// 执行HEAD请求,而不是GET。

-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 cookie-name=value 对请求附加一个Cookie:行。 其典型形式是name=value的一个参数对。此参数可以重复。

-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 proxy-auth-username:password 对一个中转代理提供BASIC认证信任。用户名和密码由一个:隔开,并以base64编码形式发送。无论服务器是否需要(即, 是否发送了401认证需求代码),此字符串都会被发送。

-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

-h Display usage information (this message)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: