Apache benchmark 使用

1. 并发测试
同时对Web服务器进行10个并发请求,直到进行到100个请求为止。
ab -n 100 -c 10 http://www.example.com/ 
2. 时间测试
下面我们使用以下命令来模拟10个用户在20秒的时间内同时访问网站:
ab -c 10 -t 20 http://www.example.com/ 
该命令不包含n标记,但默认情况下包含该标记并且使用t选项时ab将其值设置为50 000。某些情况下,使用t选项时,最大请求数可能会达到50 000,此时模拟结束。
3. url 参数问题
在windows下直接使用"&"符号添加request参数时,例如:http://localhost:8080/srv.action?method=xxxx&param1=xxx
会报错,使用"":如ab -n 10 "http://localhost:8080/srv.action?method=xxxx&param1=xxx"
4. 如何模拟post文件请求
当需要post文件时,可以使用-p参数
ab -n 10 -c 10 -p home/aa.txt "http://www.example.com/"
在java中可以通过getInputStream()获取文件内容
InputStream is = null;
is = this.getRequest().getInputStream();
int lens = this.getRequest().getContentLength();
byte[] bytes = new byte[lens];
is.read(bytes);
String resp = new String(bytes, Constants.CHAR_SET_UTF8);

结果说明:

/*整个测试持续的时间*/
Time taken for tests:   3.296875 seconds
/*完成的请求数量*/
Complete requests:      1000
/*失败的请求数量*/
Failed requests:        0
Write errors:           0

/*保持联机连接的请求数量。只有在命令行中使用-k,才能看到该属性值。*/

Keep-Alive requests:    1000
/*整个场景中的网络传输量*/
Total transferred:      1987070 bytes
/*整个场景中的HTML内容传输量*/

HTML transferred:       1494000 bytes

/*每秒钟平均处理的请求数*/
Requests per second:    303.32 [#/sec] (mean)

/*每个线程下的一组请求平均消耗时间*/

Time per request:       329.688 [ms] (mean)

/*并发的每个请求平均消耗时间*/

Time per request:       3.297 [ms] (mean, across all concurrent requests)

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

Transfer rate:          588.44 [Kbytes/sec] received

//平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题
Connection Times (ms)

min mean[+/-sd] median max
Connect: 4 646 1078.7 89 3291
Processing: 165 992 493.1 938 4712

Waiting: 118 934 480.6 882 4554
Total: 813 1638 1338.9 1093 7785

//请求在多少时间内响应
//整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间小于1093 毫秒,60% 的用户响应时间小于1247 毫秒,最大的响应时间小于7785 毫秒

Percentage of the requests served within a certain time (ms)
50% 1093
66% 1247
75% 1373
80% 1493

90% 4061
95% 4398
98% 5608
99% 7368

对failed和length的解读
若failed类型都是length,请不必担心,这些请求并没有真正的失败,只是返回页面的长度跟别的不一样而已。参考:

http://stackoverflow.com/questions/579450/load-testing-with-ab-fake-failed-requests-length

http://stackoverflow.com/questions/1512304/failed-requests-by-length-in-my-apachebench-load-test-result


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值