2007年 8月 24日 金曜日
やっぱり Sun がスキ!
DTrace のススメ - DTrace でみる mod_perl の裏側
Solaris 上の Apache Web Server にて、perl で書かれたサイトを運用している 皆様は、perl を CGI としてお使いですか?それとも mod_perl を使用していますか?
mod_perl 自体は古くからありますので、皆様も既によく知っているかもしれません。 ただ、自分は漠然と mod_perl の方が CGI の場合よりも早いらしいとしか認識して いませんでした。
そこでちょっと mod_perl について調べてみました。
"mod_perl gives you a persistent Perl interpreter embedded in your web server. This lets you avoid the overhead of starting an external interpreter and avoids the penalty of Perl start-up time, giving you super-fast dynamic content." by http://perl.apache.org/
どうやら mod_perl は、web server (apache) に持続的に使用出来る Perl インタラプタ を組み込んでしまう事で、CGI の場合 (Perl スクリプトが呼び出されるたびに外部 Perl を実行する) と比べて Perl start-up time の時間を抑制出来るという物の様です。
という事で実際に呼び出しが抑制されているのかを DTrace を使って簡単に確認 してみました。
下記 man をみると、外部プログラムの呼び出しには exec() が関わりそうです。
% man -s 2 exec
System Calls exec(2)
NAME
exec, execl, execle, execlp, execv, execve, execvp - execute
^^^^^^^^
a file
^^^^^^
そこで今回は、SolarisInternals のサイトに掲載されている exec を追跡する DTrace スクリプト "exec.d" を使って検証してみましょう。
#!/usr/sbin/dtrace -s
#pragma D option quiet
proc:::exec
{
self->parent = execname;
}
proc:::exec-success
/self->parent != NULL/
{
@[self->parent, execname] = count();
self->parent = NULL;
}
proc:::exec-failure
/self->parent != NULL/
{
self->parent = NULL;
}
END
{
printf("%-20s %-20s %s\n", "WHO", "WHAT", "COUNT");
printa("%-20s %-20s %@d\n", @);
}
では、CGI として perl が呼び出される場合を確認してみます。
まず、exec.d を実行している最中に ab(apache bench) にて、perl で書かれた
index.cgi へアクセスさせます。
ab が終了したら exec.d を "Control + C" で終了させましょう。
jse8-213% /usr/apache2/bin/ab -n 2000 -c 64 http://localhost/cgi-bin/bench/index.cgi ... ... Server Software: Apache/2.0.58 Server Hostname: localhost Server Port: 80 Document Path: /cgi-bin/bench/index.cgi Document Length: 34637 bytes Concurrency Level: 64 Time taken for tests: 6.845140 seconds Complete requests: 2000 Failed requests: 0 Write errors: 0 Total transferred: 69658374 bytes HTML transferred: 69304680 bytes Requests per second: 292.18 [#/sec] (mean) Time per request: 219.044 [ms] (mean) Time per request: 3.423 [ms] (mean, across all concurrent requests) Transfer rate: 9937.71 [Kbytes/sec] received ... ... jse8-213%
# ./exec.d ^C WHO WHAT COUNT zsh ab 1 httpd index.cgi 2045 #
dtrace の結果をみると確かに、httpd から index.cgi が多数呼び出されて いるのがわかります。
では、mod_perl を使用した場合はどうなるでしょうか。
jse8-213% /usr/apache2/bin/ab -n 2000 -c 64 http://localhost/cgi-bin/bench/index.pl ... ... Server Software: Apache/2.0.58 Server Hostname: localhost Server Port: 80 Document Path: /cgi-bin/bench/index.pl Document Length: 34637 bytes Concurrency Level: 64 Time taken for tests: 2.683551 seconds Complete requests: 2000 Failed requests: 0 Write errors: 0 Total transferred: 69699894 bytes HTML transferred: 69354862 bytes Requests per second: 745.28 [#/sec] (mean) Time per request: 85.874 [ms] (mean) Time per request: 1.342 [ms] (mean, across all concurrent requests) Transfer rate: 25364.15 [Kbytes/sec] received ... ... jse8-213%
# ./exec.d ^C WHO WHAT COUNT zsh ab 1 #
今度は確かに zsh から ab が呼び出されていますが、httpd からは、index.pl は呼び出されていない (perl インタラプタを呼び出しているのでは無く、httpd が、index.pl を実行している) 事がわかります。
mod_perl を使って exec を抑制する事で、スループット(Requests per second) が、292.18 [#/sec] から、745.28 [#/sec] にも上がりましたので、perl で 書かれたサイトを運用している場合は、mod_perl を使用する事はかなりの 効果があるようです。
また、このように DTrace を使うとアプリケーションの設定変更による動作の 違いが簡単に確認できる様になります。 SolarisInternals のサイトには他にも fork.d 等、多くの有益な dtrace スクリプトが掲載されています。
是非皆様も SolarisInternals 等を参考に DTrace を効果的に使ってみて下さい。
Posted at 05:26午後 8 24, 2007 by Naoyuki Yamada in Sun | 投稿されたコメント[0]