AB工具-服务器压力测试

Apache附带的ab工具,可以直接在Web服务器本地发起测试请求,这至关重要,因为有些时候我们需要测试的仅仅是服务器的处理性能,并不想掺杂着网络传输时间的影响。ab进行一切测试的本质都是基于HTTP的,所以可以说ab对于Web服务器软件的黑盒性能测试,获得的一切数据和计算结果,都是可以通过HTTP来解释的。

 1.验证服务器是否安装ab工具(Linux服务器)

1)使用SecureCRT连接服务器;

2)输入命令: ab -V

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/

如出现上述版本信息,则说明服务器已经安装ab工具;

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

2.使用ab命令之心压力测试

1)输入执行命令:ab -c 1200 -t 60 http://localhost:8090/login.action?username=0&password=e10adc3949ba59abbe56e057f20f883e

2)测试结果:

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 114.215.84.11 (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Completed 50000 requests
Finished 50000 requests


Server Software:        Apache-Coyote/1.1
Server Hostname:        127.0.0.1
Server Port:            8090

Document Path:          /login.action?username=0
Document Length:        49 bytes

Concurrency Level:      1200
Time taken for tests:   6.310 seconds
Complete requests:      50000
Failed requests:        0
Write errors:           0
Total transferred:      7595451 bytes
HTML transferred:       2464749 bytes
Requests per second:    7924.43 [#/sec] (mean)
Time per request:       151.430 [ms] (mean)
Time per request:       0.126 [ms] (mean, across all concurrent requests)
Transfer rate:          1175.58 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   76 142.3     57    1061
Processing:    14   72  21.8     72     267
Waiting:        1   54  18.4     53     252
Total:         36  148 145.7    133    1186

Percentage of the requests served within a certain time (ms)
  50%    133
  66%    144
  75%    150
  80%    153
  90%    162
  95%    172
  98%   1087
  99%   1127
 100%   1186 (longest request)
ab -c 1200 -t 60 http://localhost:8090/login.action?username=0&password=e10adc3949ba59abbe56e057f20f883e

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

3.参数解析

-n 1000:请求总数为1000(和-t同时出现时无效)

-c 100:并发总数为100

http://localhost:8090/login.action?username=0&password=e10adc3949ba59abbe56e057f20f883e:写请求的目标URL

-t 60:请求时间为60s


ab -c 1200 -t 60 http://localhost:8090/login.action?username=0&password=e10adc3949ba59abbe56e057f20f883e-------1200个并发用户执行60s

ab -n 7500000 -c 1200 http://localhost:8090/login.action?username=0&password=e10adc3949ba59abbe56e057f20f883e-------1200个并发用户发起7500000次请求(约并发十分钟)

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

4.测试结果解析

1)Concurrency Level :并发用户数(我们设置的参数之一)

2)Time taken for tests :所有这些请求被处理完成所花费的总时间

3)Complete requests :总请求数量(我们设置的参数之一)

4)Failed requests :失败的请求数量(失败是指请求在连接服务器、发送数据等环节发生异常,以及无响应后超时的情况)

5)Total transferred :表示所有请求的响应数据长度总和(包括每个HTTP响应数据的头信息和正文数据的长度)

6)HTML transferred 表示所有请求的响应数据中正文数据的总和(减去了Total transferred中HTTP响应数据中的头信息的长度)

7)Requests per second :吞吐率(计算公式:Complete requests / Time taken for tests)

8)Time per request: 用户平均请求等待时间(计算公式:Time token for tests/(Complete requests/Concurrency Level))

9)Time per requet(across all concurrent request) :服务器平均请求等待时间(计算公式:Time taken for tests/Complete requests,正好是吞吐率的倒数。也可以这么统计:Timeper request/Concurrency Level)

10)Transfer rate :请求在单位时间内从服务器获取的数据长度(计算公式:Total trnasferred/ Time taken for tests,这个统计很好的说明服务器的处理能力达到极限时,其出口宽带的需求量。)

11)Percentage of requests served within a certain time(ms) :描述每个请求处理时间的分布情况,比如以上测试,80%的请求处理时间都不超过6ms,这个处理时间是指前面的Time per request,即对于单个用户而言,平均每个请求的处理时间。

你可能感兴趣的:(压力测试)