天天看點

壓力測試工具

1.壓力測試webbench

 webbench最多可以模拟3萬個并發連接配接去測試網站的負載能力,個人感覺要比apache自帶的ab壓力測試工具好,安裝使用也特别友善。

  1、适用系統:linux

  2、編譯安裝:

引用

wget http://blog.zyan.cc/soft/linux/webbench/webbench-1.5.tar.gz

tar zxvf webbench-1.5.tar.gz

cd webbench-1.5

make && make install

  3、使用:

webbench -c 500 -t 30 http://127.0.0.1/test.jpg

  參數說明:-c表示并發數,-t表示時間(秒)

  4、測試結果示例:

webbench - simple web benchmark 1.5

copyright (c) radim kolar 1997-2004, gpl open source software.

benchmarking: get http://127.0.0.1/test.jpg

500 clients, running 30 sec.

speed=3230 pages/min, 11614212 bytes/sec.

requests: 1615 susceed, 0 failed.

2.壓力測試ab

ab網站壓力測試指令的參數、輸出結果的中文注解

以前安裝好apache總是不知道該如何測試apache的性能,現在總算找到一個測試工具了。就是apache自帶的測試工具ab(apache benchmark).在apache的bin目錄下。

格式: ./ab [options] [http://]hostname[:port]/path

參數:

-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

//-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而不是伺服器的性能。

參數很多,一般我們用 -c 和 -n 參數就可以了. 例如:

./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

//并發數

time taken for tests: 8.188731 seconds

//整個測試持續的時間

complete requests: 1000

//完成的請求數量

failed requests: 0

//失敗的請求數量

write errors: 0

total transferred: 1361581 bytes

//整個場景中的網絡傳輸量

html transferred: 1055666 bytes

//整個場景中的html内容傳輸量

requests per second: 122.12 [#/sec] (mean)

//大家最關心的名額之一,相當于 lr 中的 每秒事務數 ,後面括号中的 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

//平均每秒網絡上的流量,可以幫助排除是否存在網絡流量過大導緻響應時間延長的問題

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

//網絡上消耗的時間的分解,各項資料的具體算法還不是很清楚

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 毫秒

由于對于并發請求,cpu實際上并不是同時處理的,而是按照每個請求獲得的時間片逐個輪轉處理的,是以基本上第一個time per request時間約等于第二個time per request時間乘以并發請求數

四、siege

一款開源的壓力測試工具,可以根據配置對一個web站點進行多使用者的并發通路,記錄每個使用者所有請求過程的相應時間,并在一定數量的并發通路下重複進行。

官方:http://www.joedog.org/

siege下載下傳:http://soft.vpser.net/test/siege/siege-2.67.tar.gz

解壓:

# tar -zxf siege-2.67.tar.gz

進入解壓目錄:

# cd siege-2.67/

安裝:

#./configure ; make

#make install

使用

siege -c 200 -r 10 -f example.url

-c是并發量,-r是重複次數。 url檔案就是一個文本,每行都是一個url,它會從裡面随機通路的。

example.url内容:

http://www.licess.cn

http://www.vpser.net

http://soft.vpser.net

結果說明

lifting the server siege… done.

transactions: 3419263 hits //完成419263次處理

availability: 100.00 % //100.00 % 成功率

elapsed time: 5999.69 secs //總共用時

data transferred: 84273.91 mb //共資料傳輸84273.91 mb

response time: 0.37 secs //相應用時1.65秒:顯示網絡連接配接的速度

transaction rate: 569.91 trans/sec //均每秒完成 569.91 次處理:表示伺服器後

throughput: 14.05 mb/sec //平均每秒傳送資料

concurrency: 213.42 //實際最高并發數

successful transactions: 2564081 //成功處理次數

failed transactions: 11 //失敗處理次數

longest transaction: 29.04 //每次傳輸所花最長時間

shortest transaction: 0.00 //每次傳輸所花最短時間

繼續閱讀