web壓力測試工具apache -ab講解
現在很多web壓力測試工具都是收費的,但是apache卻內建了一個免費的壓力測試工具,即ab工具(命令)。具體可在Apache的根目錄下的bin目錄裡面,找到一個ab.exe檔案就是。用它可以粗略檢測一下自己的程式效能如何。
具體用法如下,摘抄自網上。如有錯誤,還請指正。
格式
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的資料的檔案.
-T content-type Content-type header for POSTing
//POST資料所使用的Content-type頭資訊。
-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. ‘Apache=1234. (repeatable)
//-C cookie-name=value 對請求附加一個Cookie:行。 其典型形式是name=value的一個參數對。此參數可以重複。
-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 參數就可以了. 例如:
開啟cmd,輸入 以下代碼。
cd C:\Apache2.2\bin
ab -n 1000 -c 100 [url]http://zf.guqin.com/index/index[/url]
這個表示同時處理100個請求並運行1000次index.php檔案。以下是列印出來的內容。
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, [url]http://www.zeustech.net/[/url]
Copyright (c) 1998-2002 The Apache Software Foundation, [url]http://www.apache.org/[/url]
Benchmarking 127.0.0.1 (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
Finished 1000 requests
Server Software: Apache/2.2.8
//平台apache 版本2.2.8
Server Hostname: zf.guqin.com
//伺服器主機名稱
Server Port: 80
//伺服器連接埠
Document Path: /index.php
//測試的頁面文檔
Document Length: 1018 bytes
//文檔大小
Concurrency Level: 1000
//並發數
Time taken for tests: 8.188731 seconds
//整個測試持續的時間
Complete requests: 1000
//完成的請求數量
Failed requests: 0
//失敗的請求數量
Write errors: 0
Total transferred: 1361581 bytes
//整個情境中的網路傳輸量
HTML transferred: 1055666 bytes
//整個情境中的HTML內容傳輸量
Requests per second: 122.12 [#/sec] (mean)
//大家最關心的指標之一,相當於 LR 中的每秒事務數,後面括弧中的 mean 表示這是一個平均值
Time per request: 8188.731 [ms] (mean)
//大家最關心的指標之二,相當於 LR 中的平均事務回應時間,後面括弧中的 mean 表示這是一個平均值
Time per request: 8.189 [ms] (mean, across all concurrent requests)
//每個請求實際已耗用時間的平均值
Transfer rate: 162.30 [Kbytes/sec] received
//平均每秒網路上的流量,可以協助排除是否存在網路流量過大導致回應時間延長的問題
Connection Times (ms)
min mean[+/-sd] median max
Connect: 4 646 1078.7 89 3291
Processing: 165 992 493.1 938 4712
Waiting: 118 934 480.6 882 4554
Total: 813 1638 1338.9 1093 7785
//網路上消耗的時間的分解,各項資料的具體演算法還不是很清楚
Percentage of the requests served within a certain time (ms)
50% 1093
66% 1247
75% 1373
80% 1493
90% 4061
95% 4398
98% 5608
99% 7368
100% 7785 (longest request)
//整個情境中所有請求的響應情況。在情境中每個請求都有一個回應時間,其中50%的使用者回應時間小於1093 毫秒,60% 的使用者回應時間小於1247 毫秒,最大的回應時間小於7785 毫秒
由於對於並發請求,cpu實際上並不是同時處理的,而是按照每個請求獲得的時間片逐個輪轉處理的,所以基本上第一個Time per request時間約等於第二個Time per request時間乘以並發請求數。
您可能感興趣的文章
- 十大最優秀的Web網站效能測試軟體工具
- php bom去除工具,php批量去除bom的代碼
- 民調顯示多數美國人預測奧巴馬將連任
- 程式員和測試員之間的經典對白。這些是國外程式員總結分享的,稱其上全球通用?
- web前端開發小工具集合
- js擷取捲軸距離瀏覽器頂部,底部的高度,相容ie和firefox
- php壓入元素到數組頭部(array_unshift的用法)
- 軟體測試工程師職業介紹和規劃
http://www.bkjia.com/PHPjc/860675.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/860675.htmlTechArticleweb壓力測試工具apache -ab講解 現在很多web壓力測試工具都是收費的,但是apache卻內建了一個免費的壓力測試工具,即ab工具(命令)。具體可...