壓力測試工具Ab簡介nginx
Apache安裝包中自帶的壓力測試工具 Apache Benchmark(簡稱ab) 簡單易用,這裏就採用 ab做爲壓力測試工具了。apache
1.獨立安裝服務器
ab運行須要依賴apr-util包,安裝命令爲: cookie
1併發
yum install apr-utilide
安裝依賴 yum-utils中的yumdownload 工具工具
若是沒有找到 yumdownload 命令能夠post
1性能
yum install yum-utils測試
安裝完成後執行如下指令
1
cd /opt
2
mkdir abtmp
3
cd abtmp
4
yum install yum-utils.noarch
5
yumdownloader httpd-tools*
6
rpm2cpio httpd-*.rpm | cpio -idmv
解開後就能獲得獨立的 ab可執行文件了。
操做完成後 將會產生一個 usr 目錄 ab文件就在這個usr 目錄中
2.參數詳解
摘自: http://www.path8.net/tn/archives/5574
-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,下面是關鍵指標含義的解釋:
Time per request: 77.936 [ms] (mean)
每批請求處理完成的平均時間
Time per request: 15.587 [ms] (mean, across all concurrent requests)
每一個請求處理完成的平均時間 =每批完成時間77.936除以併發數 5
Requests per second: 64.15 [#/sec] (mean)
每秒能處理的的請求數 =1000ms除以15.587
標籤:工具ocapacheab壓力測試yumdownload