mod_pythonなのかmod_wsgiなのか

2007/03/25 01:59

※ 商品のリンクをクリックして何かを購入すると私に少額の報酬が入ることがあります【広告表示】

mod_wsgiを適当に試してみた。

本家から苦言が…。以下はこちらもあわせてみてください。

Google Groups mod_wsgi

Read first. I tested the view include database access. So, main bottle neck might be database. Developer of mod_wsgi Graham Dumpleton said In respect of the difference between mod_python and mod_wsgi, although at the low level mod_wsgi may have less overhead than mod_python, once you add in a large WSGI application framework such as Django, because processing time is principally taken up by Django and any database accesses, you probably will not see much difference between the two.

See this mod_wsgi group's response too.

100件くらいのデータから10件を持ってきて一覧するというどこかで見たことのあるベンチ(実はネックはDBか!?)。

CoreDuo1.83位のmacbookでPostgreSQL8を使って適当にやってみただけです。

本当はメモリ使用状況とか大事なんだろうけど、適当に入れたモジュールが山ほどあって異常にデカイapacheプロセスなので放っておいた:)。一応、mod_pythonを試す時にはmod_wsgiをオフに、mod_wsgiを試す時はmod_pythonをオフにした。オフってLoad Moduleしないってことね。

確かに、mod_wsgiはそこそこ早そうな気がする(レンタルサーバに導入しやすいのであれば、間違いなく救世主。mod_php並みの普及になれば神)。

えっと、売りは何だっけ?あと何を調べればいいんだろう。

PS2 2007/03/26 (さらに追記)

Graham Dumpleton said Worse is that on Mac OS X I sometimes see 'ab' just hang for a bit for no good reason which can blow out the 'max' figure.

OSXの ab はたまにハングすることがあるので max の値がおかしくなるとのこと。

I did benchmark test again on Gentoo Linux. Tested by five times for mod_python and mod_wsgi and used the best result each.

なので、linuxでやり直してみました。

各々5回ずつテストして、一番いい結果を利用。

  -c 10 -n 5000 for 127.0.0.1

  Requests per second:    114.12 [#/sec] (mean)
  Connection Times (ms)
                min  mean[+/-sd] median   max
  Connect:        0    0   0.7      0      22
  Processing:    11   86  50.9     74     356
  Waiting:        0   86  50.9     74     356
  Total:         11   86  50.9     74     356

  mod_wsgi

  Requests per second:    115.14 [#/sec] (mean)
  Connection Times (ms)
                min  mean[+/-sd] median   max
  Connect:        0    0   0.8      0      19
  Processing:     9   86  51.2     74     354
  Waiting:        0   85  51.3     74     354
  Total:          9   86  51.2     74     354

Because there is hardly a difference, it is supposed that database access uses most of the time. Returned a page of about the same size using django.views.generic.simple.direct_to_template for without database access.

結局殆ど差がでないので、データベースアクセスでほとんどの時間を使っていると推測。

django.views.generic.simple.direct_to_template を使って、データベースアクセス無しの結果を返すようにしてみた。

  Requests per second:    1019.71 [#/sec] (mean)
  Connection Times (ms)
                min  mean[+/-sd] median   max
  Connect:        0    2   2.5      1      16
  Processing:     1    6  10.1      5     251
  Waiting:        0    5   9.6      3     243
  Total:          1    8  10.4      7     254

  mod_wsgi

  Requests per second:    1120.94 [#/sec] (mean)
  Connection Times (ms)
                min  mean[+/-sd] median   max
  Connect:        0    2   2.6      1      11
  Processing:     1    5   6.8      5     225
  Waiting:        0    4   6.6      3     224
  Total:          1    8   7.1      8     233

The difference became around 10%. File IO may become the bottleneck this time....

10%ほど差が出た。今度はファイルIOがボトルネッックになってるかも。

Finally, I use memcached backend.

最後に、memcachedを使ってみた(データベースアクセスもファイルIOも無し)。

  Requests per second:    1008.73 [#/sec] (mean)
  Connection Times (ms)
                min  mean[+/-sd] median   max
  Connect:        0    1   2.4      1      11
  Processing:     1    7   4.8      7      71
  Waiting:        0    5   5.1      5      70
  Total:          1    9   4.9      9      71

  mod_wsgi

  Requests per second:    1264.55 [#/sec] (mean)
  Connection Times (ms)
                min  mean[+/-sd] median   max
  Connect:        0    1   1.9      1       8
  Processing:     0    5   3.7      5      96
  Waiting:        0    4   3.5      3      60
  Total:          0    7   3.8      7      96

mod_wsgi is 25% faster than mod_python ?

mod_wsgiの方が25%速い?

Because speed doesn't improve much with memcached either, it may have other bottleneck like hardware limitation or something.

memcachedを使ってもあまり速度の向上が無いので、今度は別の何かがボトルネックになってるかも…

PS 2007/03/25 (追記)

mod_wsgiの開発者、Graham Dumpletonさんから「ある程度の大きさをもつDjangoのようなフレームワークを利用した場合には、余り目に見 える差は出てこない」という苦言をいただきました。

そもそも、データベースにアクセスしているので、ボトルネックがデータベースである可能性は当然高いです。mod_wsgiも安定しているなぁ、程度で見てください。

また、-n 1000のテストが(指摘通り)明らかにおかしいので、-n 100のテスト結果にしました。

/opt/local/apache2/bin/ab -c 10 -n 100 http://127.0.0.1/bench/list

  This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $>
  apache-2.0
  Copyright 1996 Adam Twiss, Zeus Technology Ltd,
  http://www.zeustech.net/
  Copyright 1997-2005 The Apache Software Foundation,
  http://www.apache.org/

  Benchmarking 127.0.0.1 (be patient).....done
  Server Software:        Apache/2.2.2
  Server Hostname:        127.0.0.1
  Server Port:            80
  Document Path:          /bench/list
  Document Length:        582 bytes
  Concurrency Level:      10
  Time taken for tests:   0.877565 seconds
  Complete requests:      100
  Failed requests:        0
  Write errors:           0
  Total transferred:      80500 bytes
  HTML transferred:       58200 bytes
  Requests per second:    113.95 [#/sec] (mean)
  Time per request:       87.757 [ms] (mean)
  Time per request:       8.776 [ms] (mean, across all concurrent requests)
  Transfer rate:          88.88 [Kbytes/sec] received
  Connection Times (ms)
                min  mean[+/-sd] median   max
  Connect:        0    0   2.5      0      20
  Processing:    18   84  48.4     71     274
  Waiting:       16   83  48.5     71     273
  Total:         22   84  48.2     72     274
  Percentage of the requests served within a certain time (ms)
   50%     72
   66%     89
   75%     93
   80%    110
   90%    171
   95%    188
   98%    200
   99%    274
  100%    274 (longest request)
/opt/local/apache2/bin/ab -c 10 -n 1000 http://127.0.0.1/bench/list

  #something wrong with my apache setting.

  This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $>
  apache-2.0
  Copyright 1996 Adam Twiss, Zeus Technology Ltd,
  http://www.zeustech.net/
  Copyright 1997-2005 The Apache Software Foundation,
  http://www.apache.org/
  Benchmarking localhost (be patient)
  Server Software:        Apache/2.2.2
  Server Hostname:        localhost
  Server Port:            80
  Document Path:          /bench/list
  Document Length:        582 bytes
  Concurrency Level:      10
  Time taken for tests:   9.287893 seconds
  Complete requests:      1000
  Failed requests:        0
  Write errors:           0
  Total transferred:      805000 bytes
  HTML transferred:       582000 bytes
  Requests per second:    107.67 [#/sec] (mean)
  Time per request:       92.879 [ms] (mean)
  Time per request:       9.288 [ms] (mean, across all concurrent requests)
  Transfer rate:          84.63 [Kbytes/sec] received
  Connection Times (ms)
                min  mean[+/-sd] median   max
  Connect:        0    0   0.2      0       3
  Processing:    15   90 433.9     39    8587
  Waiting:       15   90 433.8     39    8583
  Total:         15   90 433.9     39    8587

  Percentage of the requests served within a certain time (ms)
   50%     39
   66%     53
   75%     74
   80%    105
   90%    174
   95%    208
   98%    279
   99%    296
  100%   8587 (longest request)
/opt/local/apache2/bin/ab -c 10 -n 100 http://127.0.0.1/bench/list

  This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $>
  apache-2.0
  Copyright 1996 Adam Twiss, Zeus Technology Ltd,
  http://www.zeustech.net/
  Copyright 1997-2005 The Apache Software Foundation,
  http://www.apache.org/
  Benchmarking 127.0.0.1 (be patient).....done
  Server Software:        Apache/2.2.2
  Server Hostname:        127.0.0.1
  Server Port:            80
  Document Path:          /bench/list
  Document Length:        582 bytes
  Concurrency Level:      10
  Time taken for tests:   1.267926 seconds
  Complete requests:      100
  Failed requests:        0
  Write errors:           0
  Total transferred:      80700 bytes
  HTML transferred:       58200 bytes
  Requests per second:    78.87 [#/sec] (mean)
  Time per request:       126.793 [ms] (mean)
  Time per request:       12.679 [ms] (mean, across all concurrent requests)
  Transfer rate:          61.52 [Kbytes/sec] received
  Connection Times (ms)
                min  mean[+/-sd] median   max
  Connect:        0    0   1.0      0       9
  Processing:    16   90  98.9     63     725
  Waiting:       16   89  98.9     61     724
  Total:         16   90  98.9     63     725
  Percentage of the requests served within a certain time (ms)
   50%     63
   66%     82
   75%    105
   80%    113
   90%    202
   95%    261
   98%    416
   99%    725
   100%    725 (longest request)
/opt/local/apache2/bin/ab -c 10 -n 1000 http://127.0.0.1/bench/list

  #something wrong with my apache setting.

  This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $>
  apache-2.0
  Copyright 1996 Adam Twiss, Zeus Technology Ltd,
  http://www.zeustech.net/
  Copyright 1997-2005 The Apache Software Foundation,
  http://www.apache.org/
  Benchmarking localhost (be patient)
  Server Software:        Apache/2.2.2
  Server Hostname:        localhost
  Server Port:            80
  Document Path:          /bench/list
  Document Length:        582 bytes
  Concurrency Level:      10
  Time taken for tests:   9.564653 seconds
  Complete requests:      1000
  Failed requests:        0
  Write errors:           0
  Total transferred:      807000 bytes
  HTML transferred:       582000 bytes
  Requests per second:    104.55 [#/sec] (mean)
  Time per request:       95.647 [ms] (mean)
  Time per request:       9.565 [ms] (mean, across all concurrent requests)
  Transfer rate:          82.39 [Kbytes/sec] received
  Connection Times (ms)
                min  mean[+/-sd] median   max
  Connect:        0    0   0.3      0       5
  Processing:    14   94 423.0     32    5471
  Waiting:       14   94 422.9     31    5471
  Total:         14   94 423.0     32    5471
  Percentage of the requests served within a certain time (ms)
   50%     32
   66%     53
   75%     68
   80%     82
   90%    160
   95%    265
   98%    286
   99%    321
   100%   5471 (longest request)

Prev Entry

Next Entry