ab測試工具使用

網站壓力測試
Usage: ab [options] [http[s]😕/]hostname[:port]/path
用法:ab [選項] 地址

選項:

Options are:
-n requests #執行的請求數,即一共發起多少請求。
-c concurrency #請求併發數。
-t timelimit #測試所進行的最大秒數。其內部隱含值是-n 50000,它可以使對服務器的測試限制在一個固定的總時間以內。默認時,沒有時間限制。
-s timeout #指定每個請求的超時時間,默認是30秒。
-b windowsize #指定tcp窗口的大小,單位是字節。
-B address #指定在發起連接時綁定的ip地址是什麼。
-p postfile #指定要POST的文件,同時要設置-T參數。
-u putfile #指定要PUT的文件,同時要設置-T參數。
-T content-type #指定使用POST或PUT上傳文本時的文本類型,默認是’text/plain’。
-v verbosity #設置詳細模式等級。
-w #將結果輸出到html的表中。
-i #使用HEAD方式代替GET發起請求。
-y attributes #以表格方式輸出時,設置html表格tr屬性
-z attributes #以表格方式輸出時,設置html表格th或td屬性。
-C attribute #添加cookie,比如’Apache=1234’。(可重複)
-H attribute #爲請求追加一個額外的頭部,比如’Accept-Encoding: gzip’。(可重複)
-A attribute #對服務器提供BASIC認證信任。用戶名和密碼由一個:隔開,並以base64編碼形式發送。無論服務器是否需要(即,是否發送了401認證需求代碼),此字符串都會被髮送。
-P attribute #對一箇中轉代理提供BASIC認證信任。用戶名和密碼由一個:隔開,並以base64編碼形式發送。無論服務器是否需要(即, 是否發送了401認證需求代碼),此字符串都會被髮送。
-X proxy:port #指定代理服務器的IP和端口。
-V #打印版本信息。
-k #啓用HTTP KeepAlive功能,即在一個HTTP會話中執行多個請求。默認時,不啓用KeepAlive功能。
-d #不顯示"percentage served within XX [ms] table"的消息(爲以前的版本提供支持)。
-q #如果處理的請求數大於150,ab每處理大約10%或者100個請求時,會在stderr輸出一個進度計數。此-q標記可以抑制這些信息。
-g filename #把所有測試結果寫入一個’gnuplot’或者TSV(以Tab分隔的)文件。此文件可以方便地導入到Gnuplot,IDL,Mathematica,Igor甚至Excel中。其中的第一行爲標題。
-e filename #產生一個以逗號分隔的(CSV)文件,其中包含了處理每個相應百分比的請求所需要(從1%到100%)的相應百分比的(以微妙爲單位)時間。由於這種格式已經“二進制化”,所以比’gnuplot’格式更有用。
-r #當收到錯誤時不要退出。
-h #輸出幫助信息
-Z ciphersuite 指定SSL/TLS密碼套件
-f protocol 指定SSL/TLS協議(SSL3, TLS1, TLS1.1, TLS1.2 or ALL)

Server Software: Apache/2.2.25 (服務器軟件名稱及版本信息)
Server Hostname: localhost (服務器主機名)
Server Port: 80 (服務器端口)
Document Path: /index.php (供測試的URL路徑)
Document Length: 10 bytes (供測試的URL返回的文檔大小)
Concurrency Level: 100 (併發數)
Time taken for tests: 0.247 seconds (壓力測試消耗的總時間)
Complete requests: 1000 (壓力測試的總次數)
Failed requests: 0 (失敗的請求數)
Write errors: 0 (網絡連接寫入錯誤數)
Total transferred: 198000 bytes (傳輸的總數據量)
HTML transferred: 10000 bytes (HTML文檔的總數據量)
Requests per second: 1.60 [#/sec] (mean) //吞吐速率,大家最關心的指標之一
Time per request: 6254.054 [ms] (mean) //用戶平均請求等待時間,大家最關心的指標之二
Time per request: 625.405 [ms] (mean, across all concurrent requests) //服務器平均請求處理的時間,大

demo
ab -c 100 -n 1000000 -k http://172.27.0.13/index/index

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.27.0.13 (be patient)
Completed 100000 requests
Completed 200000 requests
Completed 300000 requests
Completed 400000 requests
Completed 500000 requests
Completed 600000 requests
Completed 700000 requests
Completed 800000 requests
Completed 900000 requests
Completed 1000000 requests
Finished 1000000 requests

Server Software: swoole-http-server
Server Hostname: 172.27.0.13
Server Port: 80

Document Path: /index/index
Document Length: 7 bytes

Concurrency Level: 100
Time taken for tests: 27.154 seconds
Complete requests: 1000000
Failed requests: 0
Write errors: 0
Keep-Alive requests: 1000000
Total transferred: 166000000 bytes
HTML transferred: 7000000 bytes
Requests per second: 36827.40 [#/sec] (mean)
Time per request: 2.715 [ms] (mean)
Time per request: 0.027 [ms] (mean, across all concurrent requests)
Transfer rate: 5970.07 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 3
Processing: 0 3 0.7 3 36
Waiting: 0 3 0.7 3 36
Total: 0 3 0.7 3 36

Percentage of the requests served within a certain time (ms)
50% 3
66% 3
75% 3
80% 3
90% 3
95% 4
98% 4
99% 5
100% 36 (longest request)

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