1. 程式人生 > >apache---壓力測試工具ab.exe

apache---壓力測試工具ab.exe

linux中使用

預設安裝在/usr/bin/ab

/usr/bin/ab -n 100 -c 100 http://192.168.4.51/ci/index.php/home/login/index

-n : 請求次數

-c :併發數,即同時多少人訪問

Server Software:        web伺服器軟體及版本
Server Hostname:        請求的地址
Server Port:            請求的埠

Document Path:          請求的頁面路徑
Document Length:        頁面大小

Concurrency Level:      併發數
Time taken for tests:   測試總共花費的時間
Complete requests:      完成的請求數
Failed requests:        失敗的請求數
Write errors:           寫入錯誤
Total transferred:      總共傳輸位元組數,包含http的頭資訊等
HTML transferred:       html位元組數,實際的頁面傳遞位元組數
Requests per second:    每秒處理的請求數,伺服器的吞吐量(重要)
Time per request:       平均數,使用者平均請求等待時間
Time per request:       伺服器平均處理時間
Transfer rate:          平均傳輸速率(每秒收到的速率)

例項
Server Software:        Apache/2.2.15
Server Hostname:        192.168.4.51
Server Port:            80

Document Path:          /ci/index.php/home/login/index
Document Length:        2079 bytes

Concurrency Level:      100------------------------併發數
Time taken for tests:   1.636 seconds--------------花費的總時間
Complete requests:      100------------------------請求次數
Failed requests:        0--------------------------失敗次數
Write errors:           0
Total transferred:      246800 bytes
HTML transferred:       207900 bytes
Requests per second:    61.13 [#/sec] (mean)-----------------一秒完成多少個請求
Time per request:       1635.852 [ms] (mean)-----------------<span style="font-family: Arial, Helvetica, sans-serif;">100人請求一次的時間</span>
Time per request:       16.359 [ms] (mean, across all concurrent requests)----------------1人請求一次的時間
Transfer rate:          147.33 [Kbytes/sec] received

其它注意事項
1)
ab併發數不能大於請求數,會提示


ab: Cannot use concurrency level greater than total number of requests


2)
請求數預設不能超過1024個,會提示


socket: Too many open files (24)


可用ulimit -n命令修改,例如:ulimit -n 8192 (設定使用者可以同時開啟的最大檔案數)。


3)
併發數預設不能大於20000個,會提示


ab: Invalid Concurrency [Range 0..20000]


需要修改apache原始碼support目錄下ab.c檔案,找到:
#define MAX_CONCURRENCY 20000
將巨集定義的值改大,重新編譯安裝apache。


4)
提示


apr_socket_recv: Connection reset by peer (104)
其實併發數超過伺服器硬體負荷就會報這個錯誤

網上說是apr-util有些問題,不太穩定,多試幾次就好了。


5)
還有單獨的apache bench原始碼包,及如何單獨安裝ab教程
下載:http://apachebench-standalone.googlecode.com/files/ab-standalone-0.1.tar.bz2
安裝教程:https://code.google.com/p/apachebench-standalone/wiki/HowToBuild


6)測試時發現有如下錯誤


...
Failed requests:        998
   (Connect: 0, Receive: 0, Length: 998, Exceptions: 0)
...


是因為在測試動態頁面時,返回的長度和第一次不同,所以ab就判斷失敗了,對於動態頁面這是合理的。可參考:http://mib168.iteye.com/blog/1299990