WCAT(Web Capacity Analysis Tool)はMicrosoftのIIS開発チームが無償で公開している負荷テストツールです。
設定ファイルを用意してコマンドで実行するタイプのツールなのでJMeterと比べると扱いにくい感じしますが、軽量で簡単な負荷をかけたい時などは便利だと思います。
実行
下記から入手してインストールします。
32ビット(x86):http://www.iis.net/downloads/community/2007/05/wcat-63-%28×86%29
64ビット(x64):http://www.iis.net/downloads/community/2007/05/wcat-63-%28×64%29
インストールするとサンプルがついているのでそれを実行してみます。
コマンド実行なのでバッチファイルを作成します。
【IIS7】 MSC2008 セッションより (おまけ)のサイトを参考に作成しました。
@echo off
@REM 【ストレステスト準備】
@REM WCatをダウンロードしてインストール
@REM http://www.iis.net/downloads/community/2007/05/wcat-63-%28x86%29
@REM コマンドプロンプトを管理者権限で実行
@REM このバッチを実行(初回はファイアーウォール許可、強制リブートがある)
@REM
set WCAT="C:\Program Files\WCAT\Wcat.wsf"
set OUTPUT=report.xml
set SERVER=server_name
set SCENARIO=scenario.wcat
set SETTINGS=settings.wcat
set STDERR=log_errors.txt
set STDOUT=log_output.txt
set LOG=log_wcat.log
rm "%STDERR%"
rm "%STDOUT%"
@echo on
@REM Cscript をデフォルトにする
Cscript //H:Cscript
pause
@REM 負荷を掛けるクライアント名をカンマ区切りで指定する
%WCAT% -terminate -update -clients localhost
@REM サーバーのパフォーマンスカウンタにアクセスできるようにIPC$の接続を確立する
net use \\%SERVER%\ipc$
pause
@REM 実行
%WCAT% -terminate -run -setclients -clients localhost -o "%OUTPUT%" -t "%SCENARIO%" -f "%SETTINGS%" -s "%SERVER%" -singleip -x -stderr "%STDERR%" -stdout "%STDOUT%" > "%LOG%"
pause
テスクトップに「wcat」というフォルダを作成して上記のバッチファイルを保存します。
※ここではwcat.batとします。
負荷をかけるクライアント数や、収集するサーバーのパフォーマンスカウンタの指定をした「settings.wcat」ファイルを下記の内容で作成します。
settings
{
//--------------------------------------------------------------------------
// General controller settings
//
// clientfile - specifies the client file, relative to working dir
// server - host name of the webserver
// virtualclients - number of 'threads' per physical client
// clients - number of physical webcat client machines
//
//--------------------------------------------------------------------------
// Example:
//
// clientfile = "ubr\lcw2.light.ubr";
clients = 5;
virtualclients = 5;
//
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Performance counters (pass '-x' option to wcctl.exe to enable)
//
// interval - polling interval in seconds (default=10)
// host - host name of machine to monitor (default=webserver)
// counter - path of counter to monitor
//
//--------------------------------------------------------------------------
// Optional:
//
// Additional machines can be monitored by adding more counters blocks.
//
// Example:
//
// counters {
// host = "sqlserver"; // name of remote machine
// interval = 5;
// counter = "...";
// }
//
//--------------------------------------------------------------------------
counters
{
host = "www server"; // name of remote machine
interval = 5;
counter = "Processor(_Total)\\% Processor Time";
counter = "Processor(_Total)\\% Privileged Time";
counter = "Processor(_Total)\\% User Time";
counter = "Processor(_Total)\\Interrupts/sec";
counter = "Memory\\Available KBytes";
counter = "Process(w3wp)\\Working Set";
counter = "System\\Context Switches/sec";
counter = "System\\System Calls/sec";
counter = "Web Service(_Total)\\Bytes Received/sec" ;
counter = "Web Service(_Total)\\Bytes Sent/sec" ;
counter = "Web Service(_Total)\\Connection Attempts/sec" ;
counter = "Web Service(_Total)\\Get Requests/sec" ;
// .NET メモリ消費を計測
counter = "Process(w3wp)\\Private Bytes" ;
counter = ".NET CLR Memory(w3wp)\\% Time in GC" ;
counter = ".NET CLR Memory(w3wp)\\# Bytes in all Heaps" ;
counter = ".NET CLR Memory(w3wp)\\# Gen 0 Collections" ;
counter = ".NET CLR Memory(w3wp)\\# Gen 1 Collections" ;
counter = ".NET CLR Memory(w3wp)\\# Gen 2 Collections" ;
counter = ".NET CLR Memory(w3wp)\\# of Pinned Objects" ;
counter = ".NET CLR Memory(w3wp)\\Large Object Heap Size" ;
}
counters
{
host = "db server"; // name of remote machine
interval = 5;
counter = "Processor(_Total)\\% Processor Time";
counter = "Processor(_Total)\\% Privileged Time";
counter = "Processor(_Total)\\% User Time";
counter = "Processor(_Total)\\Interrupts/sec";
counter = "Memory\\Available KBytes";
counter = "System\\Context Switches/sec";
counter = "System\\System Calls/sec";
// SQLServerを計測
counter = "SQLServer:General Statistics\\User Connections"; // 接続中ログインユーザー数
counter = "SQLServer:General Statistics\\Logins/sec"; // 1秒あたりのログインユーザー数
counter = "SQLServer:Databases(x4l)\\Active Transactions"; // 実行中のトランザクション数
counter = "SQLServer:Databases(x4l)\\Transactions/sec"; // 1秒あたりの実行トランザクション数
counter = "SQLServer:Access Methods\\Table Lock Escalations/sec"; // 1秒あたりのロックエスカレーション数
counter = "SQLServer:Memory Manager\\Total Server Memory (KB)"; // サーバーが使用している動的メモリ総量
counter = "SQLServer:Memory Manager\\Connection Memory (KB)"; // ユーザー接続用に使用しているメモリ量
counter = "SQLServer:Memory Manager\\Lock Memory (KB)"; // ロックに使用しているメモリ量
}
//--------------------------------------------------------------------------
// Registry Key Monitors (pass '-x' option to wcctl.exe to enable)
//
// path - registry path, relative to HKLM
// name - name of registry key
// type - type of value (REG_SZ | REG_DWORD)
//
//--------------------------------------------------------------------------
// Optional:
//
// Additional registry keys can be monitored on the web server by
// adding more registry blocks to this file. Note that simple strings and
// dwords are all that webcat currently supports.
//
// Example:
//
// registry {
// path = "System\\CurrentControlSet\\Services\\Tcpip\\Parameters";
// name = "DhcpDomain";
// type = REG_SZ;
// }
//
//--------------------------------------------------------------------------
// registry
// {
// path = "System\\CurrentControlSet\\Control\\FileSystem";
// name = "NtfsDisableLastAccessUpdate";
// type = REG_DWORD;
// }
// registry
// {
// path = "System\\CurrentControlSet\\Services\\Tcpip\\Parameters";
// name = "SynAttackProtect";
// type = REG_DWORD;
// }
}
負荷をかけたいサイトへのリクエストをシナリオとして「scenario.wcat」ファイルを作成します。
scenario
{
name = "WCAT Script";
warmup = 30;
duration = 30;
cooldown = 10;
default
{
// send keep-alive header
setheader
{
name = "Connection";
value = "keep-alive";
}
// set the host header
setheader
{
name = "Host";
value = server();
}
setheader
{
name = "Accept-Language";
value = "ja";
}
setheader
{
name="Accept-Encoding";
value="gzip, deflate";
}
setheader
{
name="User-Agent";
value="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; Media Center PC 6.0; InfoPath.3)";
}
cookies = true;
// HTTP1.1 request
version = HTTP11;
// keep the connection alive after the request
close = ka;
}
transaction
{
weight = 1000;
request
{
url = "/hoge/";
statuscode = 401;
}
request
{
url = "/hoge/";
authentication = NTLM;
username = "userid";
password = "password";
statuscode = 401;
}
request
{
url = "/hoge/";
authentication = NTLM;
statuscode = 200;
}
request
{
url = "/hoge/hoge.aspx";
statuscode = 200;
addheader
{
name="Referer";
value="http://www.hoge.com/hoge/";
}
}
//
// specifically close the connection after both files are requested
//
close
{
method = reset;
}
}
}
「C:\Program Files\wcat」フォルダにある「report.xsl」も「wcat」フォルダへコピーします。このファイルは結果として出力されるXMLファイルをブラウザで見やすく変換してくれるスタイルシートです。
コマンドプロンプトを管理者権限で実行し、「wcat.bat」を実行すると設定された内容にしたがってサーバーへアクセスが実行されます。
※初回はファイアーウォールの許可、強制再起動が実施されます。
このバッチでは3つのログと結果が出力されます。
結果ファイルの「report.xml」をダブルクリックしてブラウザで開くと結果が参照できます。
実際のテストでは「scenario.wcat」と「settings.wcat」のファイルを環境に合わせて修正して実行します。
結果の表示は「report.xsl」を編集すると変えられます。
試しに Twitter Bootstrap を適用した「report.xsl」を含めソースは下記にアップしてあります。
https://github.com/miyabis/wcat
参考
http://blogs.technet.com/b/hirookun/archive/2008/10/11/3135065.aspx
http://blogs.technet.com/b/hirookun/archive/2007/09/15/iis7-how-to-web-wcat.aspx
http://blogs.technet.com/b/hirookun/archive/2008/04/22/_1030_iis7_1130_-msc2008-_bb30c330b730e730f33088308a30_-_08ff4a307e30513009ff_.aspx