一聚教程网:一个值得你收藏的教程网站

热门教程

apache压力测试工具ab测试使用解析

时间:2022-06-30 17:58:35 编辑:袖梨 来源:一聚教程网

ab是一款很好用的压力测试工具,linux自带不需要另外安装,一下是ab其中的几个关键参数 还有 使用实例
Requests per second:每秒多少请求,这个是非常重要的参数数值,服务器的吞吐量
Time per request: 用户平均请求等待时间
Time per request:服务器平均处理时间,也就是服务器吞吐量的倒数
Transfer rate:每秒获取的数据长度

例如,百度的压力测试 1000个请求 50个并发

ab -n 1000 -c 50 http://www.111com.net/

结果如下

[root@JOE-PC ~]# ab -n 1000 -c 50 http://www.111com.net/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>

 
Benchmarking www.111com.net (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
 
Server Software: BWS/1.0
Server Hostname: www.111com.net
Server Port: 80
 
Document Path: /
Document Length: 10969 bytes
 
Concurrency Level: 50
Time taken for tests: 12.321 seconds
Complete requests: 1000
Failed requests: 452
(Connect: 0, Receive: 0, Length: 452, Exceptions: 0)
Write errors: 0
Total transferred: 11343952 bytes
HTML transferred: 10794566 bytes
Requests per second: 81.16 [#/sec] (mean)
Time per request: 616.039 [ms] (mean)
Time per request: 12.321 [ms] (mean, across all concurrent requests)
Transfer rate: 899.14 [Kbytes/sec] received
 
Connection Times (ms)
min mean[+/-sd] median max
Connect: 6 174 341.0 87 3085
Processing: 6 363 516.3 207 5062
Waiting: 4 153 135.3 106 1502
Total: 23 536 611.3 295 5152
 
Percentage of the requests served within a certain time (ms)
50% 295
66% 396
75% 661
80% 771
90% 1282
95% 1569
98% 2499
99% 3535
100% 5152 (longest request)

ApacheBench参数说明

格式:ab [options] [http://]hostname[:port]/path
参数说明:
-n requests Number of requests to perform
//在测试会话中所执行的请求个数(本次测试总共要访问页面的次数)。默认时,仅执行一个请求。
-c concurrency Number of multiple requests to make
//一次产生的请求个数(并发数)。默认是一次一个。
-t timelimit Seconds to max. wait for responses
//测试所进行的最大秒数。其内部隐含值是-n 50000。它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。
-p postfile File containing data to POST
//包含了需要POST的数据的文件,文件格式如“p1=1&p2=2”.使用方法是 -p 111.txt 。 (配合-T)
-T content-type Content-type header for POSTing
//POST数据所使用的Content-type头信息,如 -T “application/x-www-form-urlencoded” 。 (配合-p)
-v verbosity How much troubleshooting info to print
//设置显示信息的详细程度 – 4或更大值会显示头信息, 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。 -V 显示版本号并退出。
-w Print out results in HTML tables
//以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。
-i Use HEAD instead of GET
// 执行HEAD请求,而不是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. -C “c1=1234,c2=2,c3=3″ (repeatable)
//-C cookie-name=value 对请求附加一个Cookie:行。 其典型形式是name=value的一个参数对。此参数可以重复,用逗号分割。
提示:可以借助session实现原理传递 JSESSIONID参数, 实现保持会话的功能,如
-C ” c1=1234,c2=2,c3=3, JSESSIONID=FF056CD16DA9D71CB131C1D56F0319F8″ 。
-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.
//-P proxy-auth-username:password 对一个中转代理提供BASIC认证信任。用户名和密码由一个:隔开,并以base64编码形式发送。无论服务器是否需要(即, 是否发送了401认证需求代码),此字符串都会被发送。
-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)
//-attributes 设置属性的字符串. 缺陷程序中有各种静态声明的固定长度的缓冲区。另外,对命令行参数、服务器的响应头和其他外部输入的解析也很简单,这可能会有不良后果。它没有完整地实现 HTTP/1.x; 仅接受某些’预想’的响应格式。 strstr(3)的频繁使用可能会带来性能问题,即你可能是在测试ab而不是服务器的性能。

参数很多,一般我们用 -c 和 -n 参数就可以了。

热门栏目