1. 程式人生 > >apache ab壓力測試工具---linux(ubuntu)

apache ab壓力測試工具---linux(ubuntu)

linux下開啟ab的man頁面,介紹如下:

NAME
       ab - Apache HTTP server benchmarking tool

SYNOPSIS
       ab [ -A auth-username:password ] [ -b windowsize ] [ -c concurrency ] [ -C cookie-name=value ] [ -d ] [ -e csv-file ] [ -f protocol ] [ -g gnuplot-file ] [ -h ] [ -H custom-header
       ] [ -i ] [ -k ] [ -n requests ] [ -p POST-file ] [ -P proxy-auth-username:password ] [ -q ] [ -r ] [ -s ] [ -S ] [ -t timelimit ] [ -T content-type ] [ -u PUT-file  ]  [  -v  ver?
       bosity] [ -V ] [ -w ] [ -x <table>-attributes ] [ -X proxy[:port] ] [ -y <tr>-attributes ] [ -z <td>-attributes ] [ -Z ciphersuite ] [http[s]://]hostname[:port]/path

SUMMARY
       ab  is  a  tool  for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs.
       This especially shows you how many requests per second your Apache installation is capable of serving.

每個引數的介紹,網上已經有很多了,比較實用使用的2個引數是 

-c   併發連線數

-n  請求總數

Options are:
    -n requests     Number of requests to perform
    -c concurrency  Number of multiple requests to make
使用這2個引數分別對一個weblogic伺服器和nginx進行簡單測試,可以看出簡單的區別

以下是使用ab對淘寶的nginx伺服器(tengine)進行測試的結果:

[email protected]:~$ ab  -c 100 -n 1000 http://192.168.7.15/xxhfgz/
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 192.168.7.15 (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:        Tengine/2.0.1
Server Hostname:        192.168.7.15
Server Port:            80

Document Path:          /xxhfgz/
Document Length:        17416 bytes

Concurrency Level:      100
Time taken for tests:   11.452 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      17714000 bytes
HTML transferred:       17416000 bytes
Requests per second:    87.32 [#/sec] (mean)                              #這個很關鍵,伺服器每秒處理的請求數--可以簡單理解為負載能力
Time per request: 1145.234 [ms] (mean) #每個請求使用者等待的時間 Time per request: 11.452 [ms] (mean, across all concurrent requests) Transfer rate: 1510.51 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 3 4.6 1 48 Processing: 49 1095 193.9 1161 1221 Waiting: 49 1092 196.6 1159 1216 Total: 60 1098 191.8 1163 1222 Percentage of the requests served within a certain time (ms) 50% 1163 #請求時間1163ms以下的佔50% 66% 1173 #請求時間1173ms以下的佔66% 75% 1178 80% 1181 90% 1188 95% 1194 98% 1203 99% 1206 100% 1222 (longest request)

以下是直接對weblogic伺服器進行測試結果:
[email protected]:~$ ab  -c 100 -n 1000 http://192.168.7.15:7003/xxhfgz/
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 192.168.7.15 (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:        
Server Hostname:        192.168.7.15
Server Port:            7003

Document Path:          /xxhfgz/
Document Length:        17416 bytes

Concurrency Level:      100
Time taken for tests:   18.351 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      17668000 bytes
HTML transferred:       17416000 bytes
Requests per second:    54.49 [#/sec] (mean)
Time per request:       1835.124 [ms] (mean)
Time per request:       18.351 [ms] (mean, across all concurrent requests)
Transfer rate:          940.20 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    4   8.8      1      74
Processing:    54 1768 290.3   1816    2358
Waiting:       52 1766 289.9   1814    2357
Total:         90 1772 284.9   1817    2378

Percentage of the requests served within a certain time (ms)
  50%   1817
  66%   1847
  75%   1887
  80%   1905
  90%   1931
  95%   2041
  98%   2247
  99%   2301
 100%   2378 (longest request)