Starletのヘッダとボディを合わせて出力する閾値を変更してみる
Starletは小さいコンテンツを出力する時に、ヘッダをボディを一括で出力する機能がある。今(0.17_1)での閾値は 1024byte。
これを変更して変化があるかどうかを確認する。変更点は↓の部分。
diff --git a/lib/Starlet/Server.pm b/lib/Starlet/Server.pm index 71b87f0..2cb7c3e 100644 --- a/lib/Starlet/Server.pm +++ b/lib/Starlet/Server.pm @@ -262,7 +262,7 @@ sub _handle_response { push @lines, "\015\012"; if (defined $body && ref $body eq 'ARRAY' && @$body == 1 - && length $body->[0] < 1024) { + && length $body->[0] < 8192) { # combine response header and small request body $self->write_all( $conn, join('', @lines, $body->[0]), $self->{timeout},
kazuhoさんの Kazuho@Cybozu Labs: TCP通信ではデータの送信をまとめて行うべき、もうひとつの理由(& サーバのベンチマーク手法の話) の記事も参考にしつつ、別のサーバからとローカルホストからabをかけてベンチマークする。
テスト環境は、Xeon L5630 (2.13GHz) 4コア8スレッド x 2 のサーバ。OSはCentOS 5、perlは5.16.3。
アプリケーションは約8KBのコンテンツを出力する
my $size = 8000; my $content="x"x $size; sub{[200,['Content-Type','text/html','Content-Length'=>$size],[$content]]}
Webサーバの起動は以下。
$ perl -Mlib=extlib/lib/perl5 ./extlib/bin/plackup -E production -Ilib \ -s Starlet -p 5321 --max-workers 50 \ --max-reqs-per-child 100000 --max-keepalive-reqs 1000000 -a test.psgi
別サーバからab
abを別のサーバから実行。スペックは同じ
$ ab -c 1 -n 20000 http://10.xx.xx.xx:5321/
threshold 1024
-c 1 Requests per second: 1911.63 [#/sec] (mean) -c 4 Requests per second: 6469.82 [#/sec] (mean) -c 8 Requests per second: 10203.74 [#/sec] (mean) -c 16 Requests per second: 13674.10 [#/sec] (mean) -c 32 Requests per second: 13734.97 [#/sec] (mean)
threshold 8192
-c 1 Requests per second: 2111.85 [#/sec] (mean) -c 4 Requests per second: 6579.87 [#/sec] (mean) -c 8 Requests per second: 10382.23 [#/sec] (mean) -c 16 Requests per second: 13872.82 [#/sec] (mean) -c 32 Requests per second: 13883.55 [#/sec] (mean)
ほとんど差がない
localhostから
同じサーバからabを実行
$ ab -c 1 -n 20000 http://127.0.0.1:5321/
threshold 1024
-c 1 Requests per second: 3015.53 [#/sec] (mean) -c 4 Requests per second: 9879.86 [#/sec] (mean) -c 8 Requests per second: 12516.08 [#/sec] (mean) -c 16 Requests per second: 12838.06 [#/sec] (mean) -c 32 Requests per second: 12281.61 [#/sec] (mean)
threshold 8192
-c 1 Requests per second: 3852.66 [#/sec] (mean) -c 4 Requests per second: 10992.51 [#/sec] (mean) -c 8 Requests per second: 13466.99 [#/sec] (mean) -c 16 Requests per second: 13344.34 [#/sec] (mean) -c 32 Requests per second: 13475.24 [#/sec] (mean)
コンテキストスイッチの回数がリモートから実行するより増えるので、差が大きくなると思われる。
コンテンツのサイズにもよりますが、リバースプロキシとアプリケーションサーバを同じホストに載っけている場合は、閾値が変更できると嬉しいかもしれない