lighttpdのlinux-aioサポートの記事を読んでいて気になったので、既にaioをサポートしているPerlbalの静的コンテンツを配信するWebサーバとしての性能を調べてみた。
                              サーバは
                                 CPU Pen4 2.8GHz ( HyperThreading付き) 
                                 Memory 512MB 
                                 FedoraCore6
                                 な環境です。
                              上記の記事の様にファイルを3GBほど作成(メモリーより明らかに多い量)
                                 小さい画像ファイルと見立てて、3KBのファイルを10*100*1000=1M個作成しました。
                              
                              
#/bin/bash
for i in `seq 1 10`; do 
  for k in `seq 1 100`; do 
    mkdir -p $i/$k; 
    for j in `seq 1 1000`; do 
      dd if=/dev/zero of=$i/$k/$j bs=3k count=1 2> /dev/null; 
    done; 
  done;
done
                              
                                 負荷試験はhttp_loadを使いました。
                                 別のマシン(intel iMac 1.83GHz)からリクエストをかけています。
                                 なお、このテストを行う前に、何度かパターンを変えながらテストを行っていて、いくつかのファイルについてはCacheに乗っているだろうという状態です。最後に以下の3つのテストを連続して行いました。
                              
                              ■lighttpd 1.4.13(fc6のrpm)
                                 ・設定
                              
                              
server.document-root="/var/www/html"
server.port=8080
server.event-handler="linux-sysepoll"
                              
                                 ・結果
                              
                              
$ ./http_load-12mar2006/http_load -verbose -parallel 100 -fetches 10000 url_files
--- 60.0036 secs, 5396 fetches started, 5297 completed, 99 current
10000 fetches, 100 max parallel, 3.072e+07 bytes, in 114.526 seconds
3072 mean bytes/connection
87.3162 fetches/sec, 268235 bytes/sec
msecs/connect: 0.23497 mean, 4.966 max, 0.098 min
msecs/first-response: 1135.8 mean, 2108.87 max, 14.614 min
HTTP response codes:
  code 200 -- 10000
                              
                                 ただし、この時に、CPUのwaitが、50%に張り付いている(hyperthreadingで片方のCPUを使い切った状態?)
                              
                              
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  1     64   6216 136024 223312    0    0   407   394 1593  252  0  1 49 50  0
 0  1     64   5984 136072 223584    0    0   417   376 1608  257  0  1 49 50  0
 0  1     64   6208 136032 223356    0    0   407   394 1604  252  0  1 49 50  0
 0  2     64   6568 136000 222848    0    0   346   722 1453  238  0  1 47 51  0
 0  1     64   5900 136032 223448    0    0   301   774 1388  233  0  2 49 49  0
                              
                                 なので、対応策として、max-workerを増やすしてさらにlighttpdのテスト
                              ■lighttpd 1.4.13 max-worker=4
                                 ・設定
                              
                              
server.document-root="/var/www/html"
server.port=8080
server.max-worker=4
server.event-handler="linux-sysepoll"
                              
                                 ・結果
                              
                              
$ ./http_load-12mar2006/http_load -verbose -parallel 100 -fetches 10000 url_files
--- 60 secs, 5808 fetches started, 5708 completed, 100 current
10000 fetches, 100 max parallel, 3.072e+07 bytes, in 107.158 seconds
3072 mean bytes/connection
93.3204 fetches/sec, 286680 bytes/sec
msecs/connect: 0.23277 mean, 4.663 max, 0.097 min
msecs/first-response: 1055.08 mean, 4238.66 max, 16.947 min
HTTP response codes:
  code 200 -- 10000
                              
                                 waitも50%を超えるようになって若干性能向上。
                              ■Perlbal version 1.52
                                 ・設定
                              
                              
CREATE SERVICE websrv
  SET listen         = 0.0.0.0:8080
  SET role           = web_server
  SET docroot        = /var/www/html
  SET dirindexing    = 0
  SET persist_client = on
ENABLE websrv
                              
                                 ・結果
                              
                              
./http_load-12mar2006/http_load -verbose -parallel 100 -fetches 10000 url_files
--- 60.0001 secs, 6573 fetches started, 6473 completed, 100 current
10000 fetches, 100 max parallel, 3.072e+07 bytes, in 96.3537 seconds
3072 mean bytes/connection
103.784 fetches/sec, 318825 bytes/sec
msecs/connect: 0.240852 mean, 4.551 max, 0.096 min
msecs/first-response: 480.681 mean, 3390.38 max, 80.841 min
HTTP response codes:
  code 200 -- 10000
                              
                                 ■結果
                                 結果からすれば、Perlbalの方が速い。これは意外だった。
                                 cacheに乗り切らないファイルの量だと、epollだとか使ってても結局iowaitがボトルネックになる。aioはこの問題を解決する一つの方法かも。(Apacheだとここをthreadを増やしたり、プロセスを増やしたりで対応できていると思う)
                                 ただ、Perlbalをユーザからのリクエストを受ける場所に持っていくのはちょっと抵抗があるなぁってことで、lighttpd 1.5に期待。