用ab进行性能测试

发表于:2010-7-22 11:14

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:KimSoft(csdnblog)    来源:51Testing软件测试网采编

  ab是Apache服务器自己带的性能测试工具,用它可以对指定的URL进行模拟访问,然后生成一份有关访问效率的报表,从中可以大概看出网站在高压力情况下的表现。

  Windows下的ab.exe一般都在Apache安装目录的bin目录下。这里举几个我实际中用过的例子:

  对http://localhost/dz7/index.php产生400次请求

  ab -n 400 http://localhost/dz7/index.php

  测试完成后,ab会输出测试的结果:

Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests

Server Software:        Apache/2.2.11
Server Hostname:        localhost
Server Port:            80

Document Path:          /dz7/index.php
Document Length:        7015 bytes

Concurrency Level:      1
Time taken for tests:   21.623 seconds
Complete requests:      400
Failed requests:        399
(Connect: 0, Receive: 0, Length: 399, Exceptions: 0)
Write errors:           0
Total transferred:      2968811 bytes
HTML transferred:       2805205 bytes
Requests per second:    18.50 [#/sec] (mean)
Time per request:       54.057 [ms] (mean)
Time per request:       54.057 [ms] (mean, across all concurrent requests)
Transfer rate:          134.08 [Kbytes/sec] received

Connection Times (ms)
min  mean[+/-sd] median   max
Connect:        0    0   1.3      0      16
Processing:    31   54  64.5     47    1265
Waiting:       16   51  64.3     47    1250
Total:         31   54  64.5     47    1265

Percentage of the requests served within a certain time (ms)
50%     47
66%     47
75%     47
80%     47
90%     47
95%     62
98%    141
99%    187
100%   1265 (longest request)

  参数-n设定请求的次数;另外,还可以用-c来设定并发访问数,例如要模拟50个并发访问,可以用

  ab -n 400 -c 50 http://localhost/dz7/index.php

  此外,还有一个实际的问题,就是如何用ab来模拟已登录的用户的访问。绝大部分程序的登录机制都是用Cookie+Session来实现的,浏览器在每次请求时都发送一个Cookie,里面记录了Session的SID。你可以先在利用Firefox的Firebug插件来确定Cookie里的内容是什么。



  firebug_cookie

  从中可以看到表示登录用户的内容是“QfI_sid=55ySsk”。ab可以用-C(大写的C)来设定每次请求用发送的Cookie。所以

  ab -n 400 -c 50 -C "QfI_sid=55ySsk" http://localhost/dz7/index.php

  就可以模拟已登录用户的400次访问,并发数为50的情况。
41/41234>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号