最近のPerl WAFをベンチマークした
試したのは以下。
- Catalyst -- 元祖WAF
- Mojolicious -- 軽量WAF
- Dancer -- 軽量WAF
- Amon2 -- シンプルWAF
- Amon2::Lite
- Amon2(Flavor::Minimum)
- Kossy -- ISUCONのWAF
Web Application Frameworkなので、HTMLの出力を測定。
またテンプレートエンジンにはText::Xslate(1.5007)、PSGIでWebサーバにはStarmanを使用した。
起動してから1回はアクセスしてテンプレートキャッシュは作った状態にした。
$ ./ab -n 1000 -c 50 http://127.0.0.1:5000/
結果
WAF | VERSION | Requests per second[#/sec] (mean) |
---|---|---|
Amon2Minimum | (3.32(Amon2)) | 1228.41 |
Kossy | 0.07 | 1145.12 |
追加Amon2(without Plack::Session::Store::DBI) | 3.32 | 823.95 |
Amon2Lite | 0.07 | 796.62 |
Dancer | 1.3093 | 578.38 |
Mojo | 2.57 | 539.40 |
Catalyst | 5.90010 | 323.95 |
Amon2 | 3.32 | 49.68 |
2012/3/5 23:00 追記
コメントいただきました。
amon2が遅いのはapp.psgiのPlack::Session::Store::DBIが効いちゃってるからだと思います。たぶん / “最近のPerl WAFをベンチマークした - Perl日記” htn.to/f5gwGv
— とりつよさん (@toritori0318) 3月 5, 2012
ありがとうございます。なるほど。
無意識に、Amon2が遅いことから目を背けていました。なんてこと。反省。
Plack::Session::Store::DBIを抜いてやってみると、Amon2Liteよりも早くなりました。
下にいじった箇所の追記も。
</追記>
さすがに
Amon2のMinimumはディスパッチャを挟まないままレンダリングさせたので、爆速となった。
そういう単一のURLだけのレスポンスなら最強かな。すごく限定される用途になりそうだけど。
感想
ベンチマークしておいてなんだけど、まあ余程のことがない限り好きなのを使うべきだと思う。
ただCatalystを除いて、最近はSinatraishというか、get '/' => sub {};の書き方が鉄板になってきてるみたいなので、乗り換えるのは割と簡単だと思う。
補足
いじった箇所
テンプレートを使うところ以外なし。
つまりデフォルトで使用するものは使用したままのベンチとなっている。
あ、CatalystのDebugだけログが出てくるのでカットした。
Catalyst
use Catalyst qw/ ConfigLoader Static::Simple /;
sub index :Path :Args(0) { my ( $self, $c ) = @_; $c->stash->{word} = 'ベンチマーク'; }
Mojo
package MojoBench::Root; use Mojo::Base 'Mojolicious::Controller'; use Text::Xslate; use utf8; my $tx = Text::Xslate->new({ path => ["templates"] }); sub index { my $self = shift; $self->render_text($tx->render('index.tt' => { word => 'ベンチマーク' })); } 1;
Dancer
template: "xslate"
get '/' => sub { template 'index', { word => 'ベンチマーク' }, { layout => 0 }; };
Amon2
any '/' => sub { my ($c) = @_; $c->render('index.tt', { word => 'ベンチマーク' }); };
Amon2::Lite
get '/' => sub { my ($c) = @_; $c->render('index.tt', { word => 'ベンチマーク' }); };
Amon2(Flavor::Minimum)
sub dispatch { my ($c) = @_; $c->render('index.tt', { word => 'ベンチマーク' }); }
Kossy
get '/' => sub { my ( $self, $c ) = @_; $c->render('index.tt', { word => "ベンチマーク" }); };
<追記>
Amon2(without Plack::Session::Store::DBI)
#use Plack::Session::Store::DBI; use Plack::Session::State::Cookie; ... enable 'Plack::Middleware::Session', #store => Plack::Session::Store::DBI->new( # get_dbh => sub { # DBI->connect( @$db_config ) # or die $DBI::errstr; # } #), state => Plack::Session::State::Cookie->new( httponly => 1, );
</追記>
使用テンプレート
index.tt
<!doctype html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>Benchmark</title> </head> <body> <h1><: $word :></h1> </body> </html>
その他1
MacOS Lion 10.7.3 で Catalystがインストールできなかった。build.logには次のようなエラーメッセージが出ていた。
Error: no compiler detected to compile 'lib/Class/Load/XS.c'. Aborting
Class::Load::XSのインストールでこけていたらしい。
そーいえばLionになってコンパイラがどうとかって見たことあったっけ、と思って、CCをセットしてから再度やったらいけた。
$ export CC=/usr/bin/gcc $ cpanm Catalyst::Devel
その他2
またCatalystのデフォルトテンプレートエンジンはTemplate::Toolkitなので、次のモジュールもインストールした。
移転しました
こちらを参考にさせてもらった。ありがとうございます。
その他3
Lion標準のApachBench(ab)だとlocalhostにつながらなかった。
$ ab -n 100 http://127.0.0.1:5000/ This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient)...apr_socket_recv: Connection reset by peer (54)
のでこちらを参考にさせてもらった。ありがとうございます。
Jxck's OutPut - Lion で ab コマンドがエラー