apache壓力測試工具ab測試使用解析

來源:互聯網
上載者:User

ab是一款很好用的壓力測試工具,linux內建不需要另外安裝,一下是ab其中的幾個關鍵參數 還有 使用執行個體
Requests per second:每秒多少請求,這個是非常重要的參數數值,伺服器的輸送量
Time per request: 使用者平均請求等待時間
Time per request:伺服器平均處理時間,也就是伺服器輸送量的倒數
Transfer rate:每秒擷取的資料長度

例如,百度的壓力測試 1000個請求 50個並發

ab -n 1000 -c 50 http://www.111cn.net/

結果如下

[root@JOE-PC ~]# ab -n 1000 -c 50 http://www.111cn.net/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>

 
Benchmarking www.111cn.net (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: BWS/1.0
Server Hostname: www.111cn.net
Server Port: 80
 
Document Path: /
Document Length: 10969 bytes
 
Concurrency Level: 50
Time taken for tests: 12.321 seconds
Complete requests: 1000
Failed requests: 452
(Connect: 0, Receive: 0, Length: 452, Exceptions: 0)
Write errors: 0
Total transferred: 11343952 bytes
HTML transferred: 10794566 bytes
Requests per second: 81.16 [#/sec] (mean)
Time per request: 616.039 [ms] (mean)
Time per request: 12.321 [ms] (mean, across all concurrent requests)
Transfer rate: 899.14 [Kbytes/sec] received
 
Connection Times (ms)
min mean[+/-sd] median max
Connect: 6 174 341.0 87 3085
Processing: 6 363 516.3 207 5062
Waiting: 4 153 135.3 106 1502
Total: 23 536 611.3 295 5152
 
Percentage of the requests served within a certain time (ms)
50% 295
66% 396
75% 661
80% 771
90% 1282
95% 1569
98% 2499
99% 3535
100% 5152 (longest request)

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 參數就可以了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.