Apache benchmark对网站进行压力测试

时间:2023-03-09 09:23:52
Apache  benchmark对网站进行压力测试

Apache Benchmark下载:http://down.tech.sina.com.cn/page/3132.html

ab 的全称是 ApacheBench , 是 Apache 附带的一个小工具 , 专门用于 HTTP Server 的 benchmark testing , 可以同时模拟多个并发请求。

是非常有名又小巧的压力测试工具。

下载安装apache web server 安装或解压之后,在bin\目录下有个ab执行文件。

打开运行--cmd 打开命令提示符,定位到bin\目录下。

基本用法:

ab  -c  [并发用户数]  -n  [发送请求数]   [被测试页面的URL]

设置一个用户一个请求,对百度首页加压,http://www.baidu.com/

Microsoft Windows [版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Users\daidai>d:

D:\>cd D:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin

D:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin>ab -c 2 -n 2 htt p://www.baidu.com/

This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.baidu.com (be patient).....done

Server Software:        BWS/1.1

Server Hostname:        www.baidu.com

Server Port:            80

Document Path:          /

Document Length:        92665 bytes

Concurrency Level:      2

Time taken for tests:   0.711 seconds    /* 整个测试持续的时间 * /

Complete requests:      2     /* 完成的请求数量 */

Failed requests:        1     /* 失败的请求数量 */

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

Write errors:           0

Total transferred:      187471 bytes   /* 整个场景中的网络传输量 */

HTML transferred:       185643 bytes   /* 整个场景中的 HTML 内容传输量 */

Requests per second:    2.81 [#/sec] (mean)  /* 大家最关心的指标之一,相当于 LR 中的 每秒事务数 ,后面括号中的 mean 表示这是一个平均值 */ Time per request:       711.041 [ms] (mean)   /* 大家最关心的指标之二,相当于 LR 中的 平均事务响应时间 ,后面括号中的 mean 表示这是一个平均值 */

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

Transfer rate:          257.48 [Kbytes/sec] received   /* 平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题 */

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

        min  mean[+/-sd] median   max

Connect:        8     9      0.7         9       9

Processing:   670   686  21.9      701     701

Waiting:       12     13    0.7        13      13

Total:        679     694   21.2      709     709

/* 下面的内容为整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中 50 % 的用户响应时间小于 3064 毫秒, 60 % 的用户响应时间小于 3094 毫秒,最大的响应时间小于 3184 毫秒 */

Percentage of the requests served within a certain time (ms)

50%    709

66%    709

75%    709

80%    709

90%    709

95%    709

98%    709

99%    709

100%    709 (longest request)

从上表中我们可以看到请求的总字节数为187471 bytes;响应时间为0.711 秒。

#整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间小于275毫秒,66%的用户响应时间小于298毫秒,最大的响应时间小于11843毫秒。对于并发请求,cpu实际上并不是同时处理的,而是按照每个请求获得的时间片逐个轮转处理的,所以基本上第一个Time per request时间约等于第二个Time per request时间乘以并发请求数。

总结:在远程对web服务器进行压力测试,往往效果不理想(因为网络延时过大),建议使用内网的另一台或者多台服务器通过内网进行测试,这样得出的数据,准确度会高很多。如果只有单独的一台服务器,可以直接本地测试,比远程测试效果要准确。