linux下web压力测试工具ab使用及详解
APACHE自帶的測試工具AB(apache benchmark).在APACHE的bin目錄下。
格式: ./ab [options] [http://]hostname[:port]/path
參數(shù):
??? -n requests???? Number of requests to perform
????//在測試會話中所執(zhí)行的請求個數(shù)。默認時,僅執(zhí)行一個請求
??? -c concurrency Number of multiple requests to make
????//一次產(chǎn)生的請求個數(shù)。默認是一次一個。?
??? -t timelimit??? Seconds to max. wait for responses
????//測試所進行的最大秒數(shù)。其內(nèi)部隱含值是-n 50000。它可以使對服務器的測試限制在一個固定的總時間以內(nèi)。默認時,沒有時間限制。
??? -p postfile???? File containing data to POST
????//包含了需要POST的數(shù)據(jù)的文件.?
??? -T content-type Content-type header for POSTing
????//POST數(shù)據(jù)所使用的Content-type頭信息。
??? -v verbosity??? How much troubleshooting info to print
????//設置顯示信息的詳細程度 - 4或更大值會顯示頭信息, 3或更大值可以顯示響應代碼(404, 200等), 2或更大值可以顯示警告和其他信息。 -V 顯示版本號并退出。
??? -w????????????? Print out results in HTML tables
????//以HTML表的格式輸出結(jié)果。默認時,它是白色背景的兩列寬度的一張表。
??? -i????????????? Use HEAD instead of GET
???// 執(zhí)行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的一個參數(shù)對。此參數(shù)可以重復。
??? -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 對一個中轉(zhuǎn)代理提供BASIC認證信任。用戶名和密碼由一個:隔開,并以base64編碼形式發(fā)送。無論服務器是否需要(即, 是否發(fā)送了401認證需求代碼),此字符串都會被發(fā)送。
??? -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 設置 屬性的字符串. 缺陷程序中有各種靜態(tài)聲明的固定長度的緩沖區(qū)。另外,對命令行參數(shù)、服務器的響應頭和其他外部輸入的解析也很簡單,這可能會有不良后果。它沒有完整地實現(xiàn)HTTP/1.x; 僅接受某些'預想'的響應格式。 strstr(3)的頻繁使用可能會帶來性能問題,即, 你可能是在測試ab而不是服務器的性能。
參數(shù)很多,一般我們用 -c 和 -n 參數(shù)就可以了. 例如:
./ab -c 1000 -n 1000?http://127.0.0.1/index.php
這個表示同時處理1000個請求并運行1000次index.php文件.
#/usr/local/xiaobai/apache2054/bin/ab -c 1000 -n 1000?http://127.0.0.1/index.html.zh-cn.gb2312?
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd,?http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation,?http://www.apache.org/
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.0.54
//平臺apache 版本2.0.54
Server Hostname:??????? 127.0.0.1
//服務器主機名
Server Port:??????????? 80
//服務器端口
Document Path:????????? /index.html.zh-cn.gb2312
//測試的頁面文檔
Document Length:??????? 1018 bytes
//文檔大小
Concurrency Level:????? 1000
//并發(fā)數(shù)
Time taken for tests:?? 8.188731 seconds
//整個測試持續(xù)的時間
Complete requests:????? 1000
//完成的請求數(shù)量
Failed requests:??????? 0
//失敗的請求數(shù)量
Write errors:?????????? 0
Total transferred:????? 1361581 bytes
//整個場景中的網(wǎng)絡傳輸量
HTML transferred:?????? 1055666 bytes
//整個場景中的HTML內(nèi)容傳輸量
Requests per second:??? 122.12 [#/sec] (mean)
//大家最關心的指標之一,相當于?LR?中的?每秒事務數(shù)?,后面括號中的?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
//平均每秒網(wǎng)絡上的流量,可以幫助排除是否存在網(wǎng)絡流量過大導致響應時間延長的問題
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
//網(wǎng)絡上消耗的時間的分解,各項數(shù)據(jù)的具體算法還不是很清楚
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 毫秒
????? 由于對于并發(fā)請求,cpu實際上并不是同時處理的,而是按照每個請求獲得的時間片逐個輪轉(zhuǎn)處理的,所以基本上第一個Time per request時間約等于第二個Time per request時間乘以并發(fā)請求數(shù)
?
?
?
?
?
?
?
?
?
?
?
ab是apache自帶的一款壓力測試工具,安裝完apache后就有了,一般在/usr/bin目錄下。系統(tǒng)為CentOS。
1、安裝apache
yum install httpd
2、ab使用方法形如
ab -c 20 -n 1000 http://www.example.com/
-c:并發(fā)數(shù)
-n:總請求數(shù)
假設c為并發(fā)數(shù),n為總請求數(shù),done為已完成數(shù)。從這里可以看出ab的運作方式是創(chuàng)建c個并發(fā),同時發(fā)送c個請求,然后關閉socket連接,如果done小于n,則繼續(xù)創(chuàng)建c個并發(fā),同時發(fā)送c個請求,然后關閉socket連接,一直循環(huán),直到done等于n時退出。
3、ab運行完成后會有比較詳細的結(jié)果
?
?
Server Software: web服務器軟件及版本 Server Hostname: 請求的地址 Server Port: 請求的端口Document Path: 請求的頁面路徑 Document Length: 頁面大小Concurrency Level: 并發(fā)數(shù) Time taken for tests: 測試總共花費的時間 Complete requests: 完成的請求數(shù) Failed requests: 失敗的請求數(shù) Write errors: 寫入錯誤 Total transferred: 總共傳輸字節(jié)數(shù),包含http的頭信息等 HTML transferred: html字節(jié)數(shù),實際的頁面?zhèn)鬟f字節(jié)數(shù) Requests per second: 每秒處理的請求數(shù),服務器的吞吐量(重要) Time per request: 平均數(shù),用戶平均請求等待時間 Time per request: 服務器平均處理時間 Transfer rate: 平均傳輸速率(每秒收到的速率)?
?
4、其它注意事項
1)
ab并發(fā)數(shù)不能大于請求數(shù),會提示
ab: Cannot use concurrency level greater than total number of requests
2)
請求數(shù)默認不能超過1024個,會提示
socket: Too many open files (24)
可用ulimit -n命令修改,例如:ulimit -n 8192 (設置用戶可以同時打開的最大文件數(shù))。
3)
并發(fā)數(shù)默認不能大于20000個,會提示
ab: Invalid Concurrency [Range 0..20000]
需要修改apache源代碼support目錄下ab.c文件,找到:
#define MAX_CONCURRENCY 20000
將宏定義的值改大,重新編譯安裝apache。
4)
提示
apr_socket_recv: Connection reset by peer (104)
網(wǎng)上說是apr-util有些問題,不太穩(wěn)定,多試幾次就好了。
5)
還有單獨的apache bench源碼包,及如何單獨安裝ab教程
下載:http://apachebench-standalone.googlecode.com/files/ab-standalone-0.1.tar.bz2
安裝教程:https://code.google.com/p/apachebench-standalone/wiki/HowToBuild
6)測試時發(fā)現(xiàn)有如下錯誤
?
?
... Failed requests: 998(Connect: 0, Receive: 0, Length: 998, Exceptions: 0) ...總結(jié)
以上是生活随笔為你收集整理的linux下web压力测试工具ab使用及详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到自己七窍流血是什么意思
- 下一篇: linux 系统下配置java环境变量