服務器併發測試工具ab

apache下自帶併發測試工具ab


ApacheBench參數說明

格式:ab [options] [http://]hostname[:port]/path
參數說明:
-n requests Number of requests to perform
//在測試會話中所執行的請求個數(本次測試總共要訪問頁面的次數)。默認時,僅執行一個請求。
-c concurrency Number of multiple requests to make
//一次產生的請求個數(併發數)。默認是一次一個。
-t timelimit Seconds to max. wait for responses
//測試所進行的最大秒數。其內部隱含值是-n 50000。它可以使對服務器的測試限制在一個固定的總時間以內。默認時,沒有時間限制。
-p postfile File containing data to POST
//包含了需要POST的數據的文件,文件格式如“p1=1&p2=2”.使用方法是 -p 111.txt 。 (配合-T)
-T content-type Content-type header for POSTing
//POST數據所使用的Content-type頭信息,如 -T “application/x-www-form-urlencoded” 。 (配合-p)
-v verbosity How much troubleshooting info to print
//設置顯示信息的詳細程度 – 4或更大值會顯示頭信息, 3或更大值可以顯示響應代碼(404, 200等), 2或更大值可以顯示警告和其他信息。 -V 顯示版本號並退出。
-w Print out results in HTML tables
//以HTML表的格式輸出結果。默認時,它是白色背景的兩列寬度的一張表。
-i Use HEAD instead of GET
// 執行HEAD請求,而不是GET。
-x attributes String to insert as table attributes
-y attributes String to insert as tr attributes
-z attributes String to insert as td or th attributes
-C attribute Add cookie, eg. -C “c1=1234,c2=2,c3=3″ (repeatable)
//-C cookie-name=value 對請求附加一個Cookie:行。 其典型形式是name=value的一個參數對。此參數可以重複,用逗號分割。
提示:可以藉助session實現原理傳遞 JSESSIONID參數, 實現保持會話的功能,如
-C ” c1=1234,c2=2,c3=3, JSESSIONID=FF056CD16DA9D71CB131C1D56F0319F8″ 。
-H attribute Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’ Inserted after all normal header lines. (repeatable)
-A attribute Add Basic WWW Authentication, the attributes
are a colon separated username and password.
-P attribute Add Basic Proxy Authentication, the attributes
are a colon separated username and password.
//-P proxy-auth-username:password 對一箇中轉代理提供BASIC認證信任。用戶名和密碼由一個:隔開,並以base64編碼形式發送。無論服務器是否需要(即, 是否發送了401認證需求代碼),此字符串都會被髮送。
-X proxy:port Proxyserver and port number to use
-V Print version number and exit
-k Use HTTP KeepAlive feature
-d Do not show percentiles served table.
-S Do not show confidence estimators and warnings.
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-h Display usage information (this message)
//-attributes 設置屬性的字符串. 缺陷程序中有各種靜態聲明的固定長度的緩衝區。另外,對命令行參數、服務器的響應頭和其他外部輸入的解析也很簡單,這可能會有不良後果。它沒有完整地實現 HTTP/1.x; 僅接受某些’預想’的響應格式。 strstr(3)的頻繁使用可能會帶來性能問題,即你可能是在測試ab而不是服務器的性能。

參數很多,一般我們用 -c 和 -n 參數就可以了。例如:

# ab -c 5000 -n 600 http://127.0.0.1/index.php




ab的結果

[root@localhost www]# ab -c 10 -n 100 192.168.169.45/index.php
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.169.45 (be patient).....done


Server Software:        nginx/1.8.0
Server Hostname:        192.168.169.45
Server Port:            80


Document Path:          /index.php
Document Length:        198256 bytes


Concurrency Level:      10
Time taken for tests:   0.839 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      19855600 bytes
HTML transferred:       19825600 bytes
Requests per second:    119.20 [#/sec] (mean)
Time per request:       83.892 [ms] (mean)
Time per request:       8.389 [ms] (mean, across all concurrent requests)
Transfer rate:          23113.30 [Kbytes/sec] received


Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1    2   1.8      2       9
Processing:    24   78  34.9     63     167
Waiting:       18   65  36.3     48     156
Total:         26   80  34.5     67     167


Percentage of the requests served within a certain time (ms)
  50%     67
  66%     97
  75%    108
  80%    115
  90%    129
  95%    150
  98%    167
  99%    167
 100%    167 (longest request)


Requests per second越高說明服務器越好

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章