Apache安裝包中自帶的壓力測試工具 Apache Benchmark(簡稱ab) 簡單易用,這裏就採用 ab做爲壓力測試工具了。
1.獨立安裝nginx
經過
yum-utils
中的
yumdownload
工具下載安裝包解開後就能獲得獨立的
ab
可執行文件了。
yum install yum-utils.noarch
yumdownloader httpd-tools.x86_64
rpm2cpio httpd-*.rpm | cpio -idmv
2.參數詳解apache
-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
而不是服務器的性能。
3.輸出解讀服務器
下面隨便測試一個網頁地址,來看下
ab
輸出的各項指標的含義。
===============================================================================
[root@server23 bin]# ./ab -n 100 -c 5 http://test.com
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 test.com (be patient).....done
Server Software: nginx
Server Hostname: test.com
Server Port: 80
Document Path: /
Document Length: 0 bytes
Concurrency Level: 5
Time taken for tests: 1.559 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Non-2xx responses: 100
Total transferred: 21500 bytes
HTML transferred: 0 bytes
Requests per second: 64.15 [#/sec] (mean)
Time per request: 77.936 [ms] (mean)
Time per request: 15.587 [ms] (mean, across all concurrent requests)
Transfer rate: 13.47 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 36 37 0.7 37 39
Processing: 37 41 4.6 40 59
Waiting: 37 41 4.6 39 59
Total: 73 78 4.5 77 96
Percentage of the requests served within a certain time (ms)
50% 77
66% 78
75% 79
80% 79
90% 81
95% 95
98% 95
99% 96
100% 96 (longest request)
===============================================================================
上面測試時用
-c
參數指定併發鏈接數爲
5
,下面是關鍵指標含義的解釋: