【IIS7】 MSC2008 セッションより (おまけ)

ここでは QDIG という PHPアプリケーションを使い、WCAT6.3 を絡めつつ IIS7 の新しいキャッシュ機構を見ていくことにします。これ実際にぜひやってみてください。面白いですよ。(●^o^●)

IIS7 はインストール済みである前提です。私は全モジュール入れてやりました。

●QDIG のダウンロードと展開

まず QDIG を入手します。下記へ行ってZIP形式で入手しましょう。
https://qdig.sourceforge.net/Qdig/Download

c:\QDIG へ展開しましょう。

●WCAT6.3を入手し、インストールする

WCAT は IIS.NET から入手します。
WCat 6.3 (x86)
※x64版はこのリンクを辿って、右側のリンクから入手してくださいね。

これは.msiなので、実行してインストールするだけです。ただ、英語なので気になる方はお手軽な環境でぜひ。

●WCATの準備

WCATには元々のIIS7トップページ https://localhost ページに負荷をかけるサンプルがついています。c:\Program Files\WCAT\sample\scripts にある home.ubr と settings.ubr です。

WCATを実行するバッチをここで提供しましょう。WCAT-GO.BATとでもしてデスクトップに作ってください。

=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*v

@REM [ダウンロードしたMSIをコントローラのマシンで実行します。]
@REM WCatX86.msi を実行してインストール
@REM Completeでインストールする
@REM VistaだとUACメッセージ、許可する
@REM Readme.txtが起動するので閉じる

@REM [試験準備]
@REM コントローラに管理者権限でログオン
@REM WCATのパスへ移動
cd "\Program Files\WCAT"

@REM Cscript をデフォルトに。
Cscript //H:Cscript
pause

@REM 初期設定
@REM 空白をいれずに負荷を担当するクライアント名をカンマ区切りで指定する。
@REM コントローラ自身も含まれる場合、localhostあるいはマシン名を追加しておく。
Wcat.wsf -terminate -update -clients localhost

@REM カウンタにアクセスできるようにIPC$に繋いでおく
net use \\localhost\ipc$
pause

@REM [実行]
@REM シナリオ(サンプル:home.ubr)と設定(サンプル:settings.ubr)
Wcat.wsf -terminate -run -clients localhost -t .\samples\scripts\home.ubr -f .\samples\scripts\settings.ubr -s "localhost" -singleip -x
pause

=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*

WCAT-GO.BATを実行してください。注意!ここでマシンがリブートするかもしれません。そのつもりで。

このままだとエラーになります。settings.ubr を少しいじりましょう。メモ帳で開きます。clientsとvirtualclientsの数字を有効にします。

clients        = 10;
virtualclients = 100;

counters の上にコピー&ペーストしましょう。Example というところにこれは元々コメントアウトされて書いてあります。これで上書き保存します。もう一つ、テストが緩慢だといけないんで、home.ubr もちょっと duration のところを120秒から30秒に変えておきましょうか。

で、WCAT-GO.BATを実行してください。コマンドプロンプトの二つ目が開いてlocalhost上での負荷試験が始まります。私が実行した仮想環境では下記のようになって終わりました。

WCAT1

Status 200 のところを見てください。406/sec となっています。まあこれがスループットだと乱暴に言いましょう。また、あとでWCATを使います。

●PHPの入手と展開

これは前の投稿を見てください。PHP.NET から Non Thread-Safe Binary をゲットしましょう。c:\PHP5 にでも置きましょう。

●QDIGアプリケーションの設定

今回のテストのために Default Web Site はここでバインドを ポート 80 じゃないものに変えておきましょう。

IISマネージャでQDIGをアプリケーション設定しましょう。面倒な方はこうしましょう。
cd \windows\system32\inetsrv
appcmd add site /name:”QDIG” /bindings:http/*:80: /physicalPath:”c:\QDIG”
これでSITE、APP、VDIRができますので。

でもってIEで https://localhost へ行くと403.14エラー、当然ですな。何もファイルを指定しなかったので、ディレクトリそのものを開こうとしたのですが、許可されていないわけです。何も指定しない場合には index.php を見てほしいので、以下のようにします。

IISマネージャを開いて、QDIGサイトをクリックします。既定のドキュメントをダブルクリック。追加でindex.phpを指定してOK。実はここで一番上にあるのがパフォーマンス上 重要です。上から毎回全部チェックしますので。厳密にやるなら必要ないものは削除しちゃいましょう。QDIGサイトだけに効きますのでここでやる分にはほかに影響ありません。

さて、もう一回 IE で https://localhost へ行くと404.3 エラー。.phpをどう取り扱えばいいのか IIS7 がわからないと言ってます。IISマネージャを開いて、またQDIGサイトをクリックします。今度はハンドラマッピングをダブルクリックします。モジュールマップの追加を実行します。ここからは前の投稿と同じです。

*.php / FastCgiModule / c:\PHP5\php-cgi.exe / なんでもいいですが、PHP5

ダイアログが表示されるので はい。

もう一回 IE で https://localhost へ行くとQDIGがちゃんと動いて、Empty Gallery! となるはずです。

●画像ファイルの追加

なんでもいいのでいくつかの画像が入ったフォルダをc:\QDIGフォルダ下にコピーします。汎用的な例として、Vistaがあれば C:\Windows\Web\Wallpaper のフォルダごと使うといいでしょう。そうするとQDIGが検知して、トップページにWallpaperというフォルダができます。ちょっと画像が大きいんで、できればテストしている環境の解像度に収まるくらいのサイズの画像を集めるといいでしょう。

●WCATをQDIGに負荷をかけるように変更する

では home.ubr を少しいじって、QDIGに負荷をかけるように変えてみましょう。折角のサンプルファイルはとっておきたいので home.ubr はコピーしておきましょう。その上で元の home.ubr を変更しましょう。ページをアクセスするシナリオの箇所は request のところです。で、QDIGのページを3パターンくらいURLを入手して貼り付けます。

request
{
     url         = "/index.php?Qwd=./Wallpaper&Qiv=none&Qis=M";
     statuscode  = 200;
}

request
{
     url         = "/index.php?Qwd=./Wallpaper&Qif=img7.jpg&Qiv=none&Qis=M";
     statuscode  = 200;
}

request
{
     url         = "/index.php?Qwd=./Wallpaper&Qif=img8.jpg&Qiv=none&Qis=M”;
     statuscode  = 200;
}

こんな感じです。WCAT-GO.BAT を実行すると、、、私の仮想環境ではこんな感じに。。。35/sec ですな。厳しい。。。

WCAT2

●IIS7のキャッシュを試してみる

IIS7には色々なキャッシュ機構がありますが、まずは一つめ。IISマネージャを開いて、QDIGサイトをクリックして、出力キャッシュを実行しましょう。で、追加。拡張子には .php を入れて、今回はユーザーモードキャッシュにチェックを入れましょう。そして、詳細設定ボタンを押します。で、QDIGの場合にはクエリ文字列を使って表示をしていますからクエリ文字列の変数の方を使いましょう。Qwd,Qif,Qiv,Qis と入力してOKしましょうもう一つOKで完了。さてどうなるか。。。

WCAT3

あらぁ 1872/sec までいっちゃいました。これ Thomas Deml にキャッシュ内容の確認方法は?って聞いたらメモリ内でやってて見る方法が用意されていないんだとか。。。「作って」って言っておきました。

さて、次いってみましょう。まず、クエリ文字列のキャッシュは削除しましょう。また 追加、拡張子に.phpを入れます。今度はカーネル モード キャッシュいってみましょう。特に指定ありませんのでこれでOKします。さて。。。

WCAT4

はうぅ 2744/sec ですわ。。。すご。

ちなみにカーネル モード キャッシュを使用している場合には netsh http show cachestate を試してみてください。キャッシュ内容が実際に入っているが確認できます。

という具合に IIS7 のキャッシュはかなりパワフルです。そして上記は結構条件の悪い仮想環境での結果なので、物理環境 あるいは Disk I/Oのいい環境での数字を採るともっと差が出ることもあります。実際にMSCのデモマシンでやった時にももっと差が開き、最後の数字は5桁いってました。まあ画像のサイズがもっと800x600くらいのものだったこともあるでしょう。

ただ、今回は画像集でやったのでキャッシュがファイルの変更通知レベルで問題ないのでぜひとも使いたいシナリオになりますが、厳密なトランザクションのページでは使えないでしょう。毎回結果違うでしょうし。でもWebサーバー上の多くがそういうオンラインアプリではないでしょうからうまく活用するとかなりスループットを稼げると思います。

一度、MVPの方に圧縮は?と聞かれたことがあって、それも今度書こうと思うのですが、WCATのパラメータで転送量がないので上記と同じ手法が使えないんです。確か IIS6.0 Resource Kit に入っている古いバージョンだと転送量もあったと思うので今度それでやってみようかなと思っとります。

ということで。。。( ^^) _旦~~

= English =

[IIS7] From my sesssion – the Microsoft Conference 2008 (Appendix)

I didn’t have enough time to demo this one but it’s fun so I’ll show you here. For the English world, it’s a very famous demo from Bill Staples. But mine is step-by-step so anyone can really follow my steps here.

================

I’d like to use an application called QDIG which uses PHP and also WCAT6.3 for stress test to see how caching in IIS7 works. Please try it out yourself once you understand the details. It’s really fun… and effective.

I am assuming that IIS7 is already installed and I did this with all modules installed.

- Downloading QDIG and extracting it

First you have to get QDIG from the following as a ZIP archive.
https://qdig.sourceforge.net/Qdig/Download

Extract the ZIP file to c:\QDIG.

- Getting WCAT6.3 and installing it

You can get WCAT (FREE!) from IIS.NET. Go to the following link.
WCat 6.3 (x86)
* For x64 version, look for the link on the right after you go to the above URL.

This is delivered as an .msi file. Execute it and the installation will start.

- Prepare WCAT for testing

WCAT includes a test scenario script to stress test the IIS7 top page – https://localhost/iisstart.htm  The sample scripts are placed in c:\Program Files\WCAT\sample\scripts. home.ubr and settings.ubr.

I’ll share my .BAT file I use to execute WCAT test. Copy it as a text file and name it something like “WCAT-GO.BAT"

=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*v

@REM [Execute the downloaded .MSI file on the controller machine]
@REM Execute WCatX86.msi or WCatX64.msi
@REM Do a Complete Install
@REM If it’s a Vista machine, there will be a UAC message so accept it
@REM At the end the Readme.txt file will open in notepad so close that

@REM [Prepare for testing]
@REM Login to the controller using administrator user
@REM Move to WCAT path 
cd "\Program Files\WCAT"

@REM [Make Cscript as default]
Cscript //H:Cscript
pause

@REM [Initialization]
@REM Don’t put spaces in between when you list the client machines for stress 
@REM If the controller machine also participates, add localhost or machine name in the clients list
Wcat.wsf -terminate -update -clients localhost

@REM [Connect to IPC$ to access the performance counters]

net use \\localhost\ipc$
pause

@REM [Execute test]
@REM Scenario (Sample: home.ubr) and settings (Sample: settings.ubr)
Wcat.wsf -terminate -run -clients localhost -t .\samples\scripts\home.ubr -f .\samples\scripts\settings.ubr -s "localhost" -singleip -x 
pause

=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*

Execute WCAT-GO.BAT. Be aware that the machine might be rebooted here…

This will cause an error if you execute it as it is. Let’s touch settings.ubr a little bit. Open it with notepad. You have to activate the “clients” and “virtualclients” parameter.

clients        = 10;
virtualclients = 100;

Copy and paste these lines above “counters”. These lines exist commented in the “Example” section. After you added these lines, overwrite the file. One more thing, the test will take a while if you use the default so let’s change the “duration” parameter in home.ubr, 120 to 30 seconds.

OK, execute WCAT-GO.BAT. Another command prompt will open on the machine and the stress test will begin. On my virtual machine, the test ended with the following results.

WCAT1

Look at “Status 200” where the result is 406/sec. Very rough but let’s call this throughput in this test. We’ll use WCAT again later on.

- Get PHP and deploy it

Please look at the previous post for this. Get the Non Thread-Safe Binary from https://php.net. Extract it to   c:\PHP5.

- Configure QDIG for testing

Let’s change the bindings for the default web site something other than 80 so that the steps would be easier.

Open IIS Manager and setup the QDIG application. If you want to do it simply then execute the following.
cd \windows\system32\inetsrv
appcmd add site /name:”QDIG” /bindings:http/*:80: /physicalPath:”c:\QDIG”
This makes the SITE & APP & VDIR.

OK so let’s go to https://localhost where you will get 403.14 error. Obviously. I didn’t specify any file so IIS7 tried to access the directory itself but it is not accessible by default. Actually we want index.php to be the default document so let’s set it up.

Open IIS Manager and click the QDIG site. Double click default document and add index.php in the list. Putting it on top of the list means alot to performance so don’t forget that. IIS7 needs to check each one in the list until it hits something so if you want to be sure, delete all the others. This will effect only the QDIG application so don’t worry about the other applications.

Alright, let’s try it again. Go to https://localhost where you’ll get 404.3 error this time. It means that IIS7 can’t understand how to treat “.php” files. Open IIS Manager again and click the QDIG web site. This time double click the handler mapping icon. Add a module map. From here it is the same with the previous post.

*.php / FastCgiModule / c:\PHP5\php-cgi.exe / PHP5

A dialog will open but move on.

OK go to https://localhost again where you will see QDIG working properly showing "Empty Gallery!"

- Adding some picture files

QDIG is a picture gallery application so let's get something to show. Copy them under C:\QDIG folder. If you can't find anything, for the test use why don't you copy C:\Windows\Web\Wallpaper folder from a Vista machine. Then QDIG will pick them up and on the top page, you'll see "Wallpaper". The Vista wallpapers are quite large to fit in the default QDIG settings so it would be better if you use something more smaller like 800 x 600 or something.

- Change WCAT scripts to stress test the QDIG application

OK, let's open home.ubr and think how you can change it to stress QDIG. You always want to keep the original sample files right? So copy home.ubr and edit the original after that. The scenario is explained in the "request" section of the file. Access QDIG manually with the browser and get 3 URLs that actually works. Something like the following and replace it with the iisstart.htm and welcome.png stuff.

request
{
     url         = "/index.php?Qwd=./Wallpaper&Qiv=none&Qis=M";
     statuscode  = 200;
}

request
{
     url         = "/index.php?Qwd=./Wallpaper&Qif=img7.jpg&Qiv=none&Qis=M";
     statuscode  = 200;
}

request
{
     url         = "/index.php?Qwd=./Wallpaper&Qif=img8.jpg&Qiv=none&Qis=M”;
     statuscode  = 200;
}

Alright! Execute WCAT-GO.BAT and this is what I got in my virtual machine. 35/sec...pretty heavy.

WCAT2

- Try IIS7 caching

IIS7 has several types of caches and let's try one of them first. Open IIS Manager, click the QDIG site again, execute Output Cache. Add one, input ".php" for extensions and check the User Mode cache this time. Go to the details dialog. QDIG uses a querystring mechanism so let's try out the querystring one. Input "Qwd,Qif,Qiv,Qis" as you can see from what you got above when you changed the scenario and OK. Let's see what happens...

WCAT3

Wow! 1872/sec it says... I asked someone in the IIS team how to see what's in the cache when you use this option but the answer was there is no way for this one since it's inside memory. I hope they make something to let us do it :-)

OK, let's move on. First delete the querystring cache setting. Add one again, input ".php" and let's try the kernel mode one this time. Nothing else to specify so push OK, let's go...

WCAT4

Gosh, 2744/sec is quite something...

By the way, if you want to check inside the cache, this one you can do it by "netsh http show cachestate". You'll actually be able to see that these URLs are cached.

As you can see, the caching mechanisms in IIS7 are VERY powerful. The numbers you have seen here are from a virtual machine with a normal HDD so if it's a physical machine or you have a better Disk I/O environment, this will go up naturally. The machines I actually used at the Microsoft Conference(Launch event in Japan) showed a 5 digit figure in the last test. Well the pictures were smaller - actually some shots I took at the Asahiyama Zoo - like 800 x 600 pixel so this made it lighter too.

This example was a picture gallery so if the cache uses the file system change event to cache, this will be a perfect scenario to use the cache. But if you have a very strict transactional application, obviously you can't use it. But you saw that the setting worked by application, so if you design how you put your pages well, you can get the most out of this feature because not all the pages will be that strict. If you have something like a blog page, it will be a perfect candidate to cache.

I was once asked by a MVP, what about compression? So I'd like to try that one out and write something in the near future but the problem is WCAT6.3 doesn't show content bytes returned so I can't use the same method to do this. I think the old one in the IIS6.0 Resource Kit worked different so maybe that is one way to do it so I'm gonna try and will write something if I get an interesting result.

So see you again... :-) Have fun!!