1、ab 安裝與介紹apache
Apache Benchmark(簡稱ab) 是Apache安裝包中自帶的壓力測試工具 ,簡單易用windows
1.ab(apache benchmark)安裝api
[root@ppzy ~] yum -y install httpd-tools服務器
2.ab 或 ab -helpcookie
[root@ppzy ~]# ab網絡
ab: wrong number of arguments併發
Usage: ab [options] [http[s]://]hostname[:port]/pathapp
Options are:socket
-n requests Number of requests to performide
-c concurrency Number of multiple requests to make at a time
-t timelimit Seconds to max. to spend on benchmarking
This implies -n 50000
-s timeout Seconds to max. wait for each response
Default is 30 seconds
-b windowsize Size of TCP send/receive buffer, in bytes
-B address Address to bind to when making outgoing connections
-p postfile File containing data to POST. Remember also to set -T
-u putfile File containing data to PUT. Remember also to set -T
-T content-type Content-type header to use for POST/PUT data, eg.
'application/x-www-form-urlencoded'
Default is 'text/plain'
-v verbosity How much troubleshooting info to print
-w Print out results in HTML tables
-i Use HEAD instead of 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)
-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.
-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.
-q Do not show progress when doing more than 150 requests
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-r Don't exit on socket receive errors.
-h Display usage information (this message)
-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
-f protocol Specify SSL/TLS protocol
(SSL2, SSL3, TLS1, TLS1.1, TLS1.2 or ALL)
[root@ppzy ~]#
ab [可選的參數選項] 須要進行壓力測試的url
參數說明:
-n 即requests,用於指定壓力測試總共的執行次數。
-c 即concurrency,用於指定的併發數。
-t 即timelimit,等待響應的最大時間(單位:秒)。
-b 即windowsize,TCP發送/接收的緩衝大小(單位:字節)。
-p 即postfile,發送POST請求時須要上傳的文件,此外還必須設置-T參數。
-u 即putfile,發送PUT請求時須要上傳的文件,此外還必須設置-T參數。
-T 即content-type,用於設置Content-Type請求頭信息,例如:application/x-www-form-urlencoded,默認值爲text/plain。
-v 即verbosity,指定打印幫助信息的冗餘級別。
-w 以HTML表格形式打印結果。
-i 使用HEAD請求代替GET請求。
-x 插入字符串做爲table標籤的屬性。
-y 插入字符串做爲tr標籤的屬性。
-z 插入字符串做爲td標籤的屬性。
-C 添加cookie信息,例如:"Apache=1234"(能夠重複該參數選項以添加多個)。
-H 添加任意的請求頭,例如:"Accept-Encoding: gzip",請求頭將會添加在現有的多個請求頭以後(能夠重複該參數選項以添加多個)。
-A 添加一個基本的網絡認證信息,用戶名和密碼之間用英文冒號隔開。
-P 添加一個基本的代理認證信息,用戶名和密碼之間用英文冒號隔開。
-X 指定使用的和端口號,例如:"126.10.10.3:88"。
-V 打印版本號並退出。
-k 使用HTTP的KeepAlive特性。
-d 不顯示百分比。
-S 不顯示預估和警告信息。
-g 輸出結果信息到gnuplot格式的文件中。
-e 輸出結果信息到CSV格式的文件中。
-r 指定接收到錯誤信息時不退出程序。
-h 顯示用法信息,其實就是ab -help。
2、ab實戰使用
1.ab的使用
模擬併發請求1000次,總共請求10000次
[root@ppzy ~]# ab -c 1000 -n 10000 http://172.16.18.84:8080/v1/echo/service/hello
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.16.18.84 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: #服務器軟件名稱及版本信息
Server Hostname: 172.16.18.84 #服務器主機名
Server Port: 8080 #服務器端口
Document Path: /v1/echo/service/hello #供測試的URL路徑
Document Length: 105 bytes #供測試的URL返回的文檔大小
Concurrency Level: 1000 #併發數
Time taken for tests: 8.143 seconds #壓力測試消耗的總時間
Complete requests: 10000 #的總次數
Failed requests: 0 #失敗的請求數
Write errors: 0 #網絡鏈接寫入錯誤數
Total transferred: 2660000 bytes #傳輸的總數據量
HTML transferred: 1050000 bytes #HTML文檔的總數據量
Requests per second: 1227.98 [#/sec] (mean) #平均每秒的請求數) 這個是很是重要的參數數值,服務器的吞吐量
Time per request: 814.344 [ms] (mean) #全部併發用戶(這裏是1000)都請求一次的平均時間
Time per request: 0.814 [ms] (mean, across all concurrent requests) #單個用戶請求一次的平均時間
Transfer rate: 318.99 [Kbytes/sec] received #每秒獲取的數據長度 (傳輸速率,單位:KB/s)
Connection Times (ms)
min mean[+/-sd] median max
Connect: 28 249 516.5 28 3055
Processing: 28 295 407.3 125 4589
Waiting: 28 279 406.7 117 4589
Total: 56 544 610.6 274 4861
Percentage of the requests served within a certain time (ms)
50% 274 #50%的請求在274ms內返回
66% 593 #60%的請求在593ms內返回
75% 1057
80% 1062
90% 1313
95% 1611
98% 2357
99% 3070
100% 4861 (longest request)
[root@ppzy ~]#
2.模擬post請求
在當前目錄下建立一個文件post.txt
編輯文件post.txt寫入
cid=4&status=1
至關於post傳遞cid,status參數
ab -c 10 -n 100 -p 'post.txt' -T 'application/x-www-form-urlencoded' 'http://test.api.com/ttk/auth/info/'