tDiary のベンチマーク

tDiary はどのくらいの負荷に耐えられるのか、どのくらいの規模まで可能なのかベンチマークしてみた。 さまざまな条件に

目的

  • CGI FastCGI mod_ruby それぞれどれくらいのパフォーマンスが出るのか
  • どれくらいの規模までスケールできるか

条件と環境

  • ハードウエア
    • Pentium4 3GHz (FSB800, HT)
    • 1GB PC3200 DDR Memory (dual channel)
    • HDD Seagate ST3120023A
  • OS
    • Debian GNU/Linux (unstable)
    • linux-2.6.14.2
  • httpd
    • apache2 2.0.55-3
    • apache2-mpm-prefork
    • libapache2-mod-fastcgi 2.4.2-7
    • libapache2-mod-ruby
    • libapache2-mod-ruby 1.2.4-1
    • ログは何も吐かないようにする
    • AllowOverride? None で .htaccess を呼ばない
    • module は最低限
  • tDiary
    • 2.0.2+20050720-1
    • index.rb
      #!/usr/bin/ruby -I/usr/share/tdiary
      
      load '/usr/share/tdiary/index.rb'
      
    • index.rbx
      • index.rb と同じ
    • index.fcgi
      #!/usr/bin/ruby -I/usr/share/tdiary
      
      require 'fcgiwrap'
      FCGIWrap.each {
        load '/usr/share/tdiary/index.rb'
      }
      

測定方法

apache 付属の ab で以下のように行う。

ab -c 10 -n 1000
  • 2 回慣らしをして(メモリに載せておく、仮測定)その後、3 回測定
  • 条件をいろいろ変えて比較するのに有意なデータをとる
  • 測定時は apache 以外のデーモンを止め、他のジョブの影響を受けないようにする

仮測定(今後の測定パラメータの検討材料)結果

CGI

% ab -n 1000 -c 10 http://localhost/~tach/d/index.rb

Server Software:        Apache/2.0.55
Server Hostname:        localhost
Server Port:            80

Document Path:          /~tach/d/index.rb
Document Length:        5390 bytes

Concurrency Level:      10
Time taken for tests:   133.354114 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      5788060 bytes
HTML transferred:       5411560 bytes
Requests per second:    7.50 [#/sec] (mean)
Time per request:       1333.541 [ms] (mean)
Time per request:       133.354 [ms] (mean, across all concurrent requests)
Transfer rate:          42.38 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   3.5      0      57
Processing:   266 1319 1215.0    851   10204
Waiting:      254  893 824.7    596   10188
Total:        266 1319 1215.2    852   10204

Percentage of the requests served within a certain time (ms)
  50%    852
  66%   1248
  75%   1676
  80%   2044
  90%   3012
  95%   3830
  98%   4947
  99%   5464
 100%  10204 (longest request)
% vmstat 5
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
12  0  19556  20984  76472 513572    0    0     0     4 1028   715 89 10  0  0
11  0  19556  29820  76476 513568    0    0     0    30 1006   379 90 10  0  0
13  0  19556  23760  76140 509144    0    0     0     9 1002   371 90 10  1  0
 9  0  19556  21212  76144 505876    0    0     0    25 1005   321 90 10  0  0
10  0  19556  21088  76144 505876    0    0     0    49 1014   318 89 11  0  0
10  0  19556  31272  76168 505852    0    0     0    26 1005   316 90 10  0  0
10  0  19556  33736  76180 505840    0    0     0     4 1002   325 90 10  0  0
10  0  19556  23940  76200 505820    0    0     0    27 1005   360 90 10  0  0
12  0  19556  25924  76204 505816    0    0     0     9 1002   369 90 10  0  0
10  0  19556  21864  76220 505800    0    0     0    22 1011   370 90 10  0  0
11  0  19556  33912  76220 505800    0    0     0     9 1003   375 89 10  0  0
10  0  19556  22320  76228 505860    0    0     0    62 1014   362 90 10  0  0
11  0  19556  29884  76228 505860    0    0     0    43 1007   369 89 10  0  0
10  0  19556  22948  76276 505812    0    0     0    27 1005   366 90 10  0  0
11  0  19556  26776  76276 505812    0    0     0     9 1003   366 89 11  0  0
10  0  19556  26404  76284 505804    0    0     0    28 1005   371 89 11  0  0
10  0  19556  29372  76292 505864    0    0     1    10 1003   370 90 10  0  0
10  0  19556  28644  76300 505856    0    0     0    22 1005   371 89 10  1  0
10  0  19556  33728  76312 505844    0    0     0    10 1002   368 90 10  0  0
10  0  19556  27776  76316 505840    0    0     0    66 1009   356 89 10  0  0
 9  0  19556  29620  76316 505840    0    0     0     4 1002   332 89 10  0  0
 7  0  19556  28412  76332 505824    0    0     0    29 1006   318 90 10  0  0
14  0  19556  17544  76352 505872    0    0     0    14 1004   326 90 10  0  0
15  0  19556  19024  76364 505860    0    0     0    24 1005   319 90 10  0  0
13  0  19556  14044  76380 505844    0    0     0    10 1004   372 89 11  1  0
12  0  19556  27820  76384 505840    0    0     0    32 1005   381 89 10  0  0

mod_ruby

% ab -n 1000 -c 10 http://localhost/~tach/d/index.rbx

Server Software:        Apache/2.0.55
Server Hostname:        localhost
Server Port:            80

Document Path:          /~tach/d/index.rbx
Document Length:        5390 bytes

Concurrency Level:      10
Time taken for tests:   21.440136 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      5776530 bytes
HTML transferred:       5400780 bytes
Requests per second:    46.64 [#/sec] (mean)
Time per request:       214.401 [ms] (mean)
Time per request:       21.440 [ms] (mean, across all concurrent requests)
Transfer rate:          263.10 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max

Connect:        0   85  51.9     83     356
Processing:    40  127  54.3    126     434
Waiting:        0   93  53.4     88     412
Total:        165  212  60.6    190     668

Percentage of the requests served within a certain time (ms)
  50%    190
  66%    201
  75%    217
  80%    236
  90%    312
  95%    356
  98%    385
  99%    396
 100%    668 (longest request)
% vmstat 5
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 2  0  19552  26568  75540 464256    0    0     0    33 1040  1616 91  8  0  0
 2  0  19552  26552  75584 464212    0    0     0    21 1022  1541 93  7  0  0
 4  0  19552  26172  75584 464212    0    0     0    40 1028  1575 93  7  0  0
 2  0  19552  26220  75600 464196    0    0     0    21 1023  1599 93  7  0  0

fastcgi

何か変。同時に 1 プロセスしか起動していない.

libapache2-mod-fcgid だと問題なし.

(04:19:17) tach: fcgi はそんなに速くないな
(04:19:36) tatsuki.sugiura@gmail.com: ちゅうかこれ古いかな……
(04:19:37) tach: やるにつれて遅くなっていく
(04:19:44) tatsuki.sugiura@gmail.com: ん。そうなんですか
(04:19:56) tach: 初回が 29/sec
(04:20:01) tach: 二回目が 16/sec
(04:20:11) tach: 今3回目
(04:20:57) tach: 11/sec
(04:21:04) tatsuki.sugiura@gmail.com: うーん。何故だ……
(04:21:19) tatsuki.sugiura@gmail.com: 仕組的に言えば一番最初が一番遅い筈なんですが
(04:21:30) tach: なんだこれは
(04:21:37) tach: vmstat の値が変だ
(04:21:38) tatsuki.sugiura@gmail.com: (プロセス上げるから
(04:21:47) tach: CPU 一つしか使ってない
(04:21:53) tach: しかも
(04:22:00) tach: システム負荷が膨大
(04:22:36) tatsuki.sugiura@gmail.com: ちょっと試しに fcgiwrap.rb を http://sugi.nemui.org/pub/ruby/fcgiwrap.rb に置き換えてみてください
(04:22:59) tatsuki.sugiura@gmail.com: あと、実行中 fcgi のプロセスっていくつ上がります?
(04:23:10) tach: ひとつ
(04:23:15) tach: これが原因か
(04:23:16) tatsuki.sugiura@gmail.com: それはおかしい……
(04:23:46) tach: 8/sec (4回目
(04:23:53) tatsuki.sugiura@gmail.com: mod_fcgi か mod_fcgid どっち使ってます?
(04:23:59) tach: mod_fastcgi
(04:24:01) tatsuki.sugiura@gmail.com: あはは。素晴らしく遅い
(04:24:17) tatsuki.sugiura@gmail.com: うーむ。何か特殊な設定いるっけな……
(04:24:29) tach: インストールしたままで設定してない
(04:25:29) tach: やはり同じだ
(04:25:41) tach: > さっきの fcgiwrap でも
(04:25:56) tach: だが再起動後は速い
(04:25:58) tach: 29/sec
(04:26:11) tatsuki.sugiura@gmail.com: なんでや……
(04:26:16) tach: system 負荷が低い
(04:26:31) tach: 回数をこなすにつれて system 負荷があがっていくのかな
(04:26:33) tatsuki.sugiura@gmail.com: それ単に、後になるとrubyのGCのせいで遅くなってるとか
(04:26:53) tach: GC は system 負荷が高くなる?
(04:26:59) tach: メモリの使い方かな
(04:27:14) tatsuki.sugiura@gmail.com: いや、user のはず
(04:27:17) tatsuki.sugiura@gmail.com: うーむ
(04:27:28) tatsuki.sugiura@gmail.com: そもそも、maxProcesses のディフォルトは50らしい
(04:27:34) tatsuki.sugiura@gmail.com: のになぜ1つしか起動しないんだろう
(04:27:37) tach: 最初は 10% くらいなのが
(04:27:58) tach: 最終的には 25% くらいになる(user 負荷と同じ
(04:28:30) tach: 空きメモリがべらぼーに変わるというわけでもないし
(04:28:34) tach: 何をやってるんだろう