・ Web系SE募集 (技術開発部開発系エンジニア・Java/Tomcat 420万円~750万円)
   ・ 社内SE募集 (業務系システムの開発・社内イントラ)

Pythonの最近のブログ記事

mod_wsgi + Django で、「ApplicationGroup 、 WSGIImportScript 」を使用しない場合と、使用した場合の Apache Bench の比較結果


比較舞台となるハードウェアのスペック

CPU model : Intel(R) Pentium(R) M processor 1300MHz
MemTotal  : 774616 kB

「ApplicationGroup 、 WSGIImportScript 」を使用しない場合

1回目:Requests per second:    617.01 [#/sec] (mean)
2回目:Requests per second:    878.81 [#/sec] (mean)
top - 15:17:17 up 4 days, 16:36,  2 users,  load average: 4.57, 2.34, 1.54
Tasks:  98 total,  15 running,  83 sleeping,   0 stopped,   0 zombie
Cpu(s): 70.0%us, 23.5%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  6.5%si,  0.0%st
Mem:    774616k total,   764872k used,     9744k free,   102576k buffers
Swap:   491392k total,        0k used,   491392k free,   431428k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
24586 apache    16   0 22152  13m 2608 R  6.1  1.8   0:01.11 httpd

「ApplicationGroup 、 WSGIImportScript 」を使用した場合

1回目:Requests per second:    722.23 [#/sec] (mean)
2回目:Requests per second:    887.55 [#/sec] (mean)
top - 15:14:34 up 4 days, 16:33,  2 users,  load average: 4.34, 2.28, 1.44
Tasks:  98 total,   4 running,  94 sleeping,   0 stopped,   0 zombie
Cpu(s): 76.0%us, 18.3%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  5.7%si,  0.0%st
Mem:    774616k total,   763176k used,    11440k free,   106432k buffers
Swap:   491392k total,        0k used,   491392k free,   432604k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
24538 apache    15   0 21224  12m 2604 S  4.6  1.7   0:01.71 httpd

「ApplicationGroup 、 WSGIImportScript 」を使用した場合、使用しない場合に比べ、1回目のab( Apache Bench) では良い結果となりました。

2回目のabでは殆ど差はありませんでした。

mod_wsgi + Django で Apache Bench を ApplicationGroup と WSGIImportScript を使用た設定で行う。

mod_wsgi/VirtualHost の 設定内容:

$ cat vhost-django_with_wsgi-2.conf
LoadModule wsgi_module        modules/mod_wsgi.so

<VirtualHost *:80 >
    ServerName localhost

    DocumentRoot /home/httpd/vhost/localhost/public

    ErrorLog  "|/usr/local/apache2/bin/rotatelogs /home/httpd/vhost/localhost/logs/error_log.%Y%m%d 86400"
    CustomLog "|/usr/local/apache2/bin/rotatelogs /home/httpd/vhost/localhost/logs/access_log.%Y%m%d 86400" combined

    DirectoryIndex index.html

    <Directory   /home/httpd/vhost/localhost/public>
      AllowOverride All
      Options All
      Order allow,deny
      Allow from all
    </Directory>

        WSGIScriptAlias / "/home/httpd/vhost/django/django_with_wsgi/apache/django.wsgi"

        <Directory   /home/httpd/vhost/django/django_with_wsgi/apache>
          Order allow,deny
          Allow from all
        </Directory>

</VirtualHost>

WSGIApplicationGroup %{GLOBAL}
WSGIImportScript /home/httpd/vhost/django/django_with_wsgi/apache/django.wsgi process-group={GLOBAL} application-group=%{GLOBAL}

apache起動直後のプロセス:

$ ps aux | grep httpd
root     24206  0.0  0.9  12908  7136 ?        Ss   14:47   0:00 /usr/local/apache2/bin/httpd -k start
root     24503  0.0  0.0   2564   656 ?        S    15:10   0:00 /usr/local/apache2/bin/rotatelogs /home/httpd/vhost/localhost/logs/error_log.%Y%m%d 86400
root     24504  0.0  0.0   2560   656 ?        S    15:10   0:00 /usr/local/apache2/bin/rotatelogs /home/httpd/vhost/localhost/logs/access_log.%Y%m%d 86400
apache   24505  0.0  0.8  12908  6408 ?        S    15:10   0:00 /usr/local/apache2/bin/httpd -k start
apache   24506  0.0  0.8  12908  6408 ?        S    15:10   0:00 /usr/local/apache2/bin/httpd -k start
apache   24507  0.0  0.8  12908  6408 ?        S    15:10   0:00 /usr/local/apache2/bin/httpd -k start
apache   24508  0.0  0.8  12908  6408 ?        S    15:10   0:00 /usr/local/apache2/bin/httpd -k start
apache   24509  0.0  0.8  12908  6408 ?        S    15:10   0:00 /usr/local/apache2/bin/httpd -k start
suzu     24511  0.0  0.0   4980   760 pts/2    S+   15:10   0:00 grep httpd

Apache Bench を2回かけます。

1回目の Apache Bench:

$  ab -n 10000 -c 100  "http://localhost/hello/"
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 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


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

Document Path:          /hello/
Document Length:        35 bytes

Concurrency Level:      100
Time taken for tests:   13.846001 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      2060000 bytes
HTML transferred:       350000 bytes
Requests per second:    722.23 [#/sec] (mean)
Time per request:       138.460 [ms] (mean)
Time per request:       1.385 [ms] (mean, across all concurrent requests)
Transfer rate:          145.24 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.4      0       8
Processing:    66  137 388.5     73   13840
Waiting:       66  124 201.4     73    3744
Total:         66  137 388.6     73   13840

Percentage of the requests served within a certain time (ms)
  50%     73
  66%     77
  75%     81
  80%     83
  90%    240
  95%    410
  98%   1035
  99%   1205
 100%  13840 (longest request)

続けて2回目の Apache Bench:

$  ab -n 10000 -c 100  "http://localhost/hello/"
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 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


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

Document Path:          /hello/
Document Length:        35 bytes

Concurrency Level:      100
Time taken for tests:   11.267003 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      2062060 bytes
HTML transferred:       350350 bytes
Requests per second:    887.55 [#/sec] (mean)
Time per request:       112.670 [ms] (mean)
Time per request:       1.127 [ms] (mean, across all concurrent requests)
Transfer rate:          178.66 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    3   6.4      0     122
Processing:    19  107 175.5    102    8956
Waiting:        4   98  21.9     96     610
Total:         19  111 175.7    105    8961

Percentage of the requests served within a certain time (ms)
  50%    105
  66%    109
  75%    112
  80%    114
  90%    120
  95%    126
  98%    154
  99%    223
 100%   8961 (longest request)

メモリ使用状況(ab 2回目の時のスナップショット):

top - 15:14:34 up 4 days, 16:33,  2 users,  load average: 4.34, 2.28, 1.44
Tasks:  98 total,   4 running,  94 sleeping,   0 stopped,   0 zombie
Cpu(s): 76.0%us, 18.3%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  5.7%si,  0.0%st
Mem:    774616k total,   763176k used,    11440k free,   106432k buffers
Swap:   491392k total,        0k used,   491392k free,   432604k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
24538 apache    15   0 21224  12m 2604 S  4.6  1.7   0:01.71 httpd
24551 apache    15   0 21224  12m 2604 S  4.6  1.7   0:00.71 httpd
24506 apache    15   0 21224  12m 2604 S  4.2  1.7   0:01.68 httpd
24509 apache    15   0 21224  12m 2604 S  4.2  1.7   0:01.65 httpd
24520 apache    15   0 21224  12m 2604 S  4.2  1.7   0:03.15 httpd
24533 apache    15   0 21224  12m 2604 S  4.2  1.7   0:01.69 httpd
24534 apache    15   0 21224  12m 2604 S  4.2  1.7   0:01.66 httpd
24535 apache    15   0 21224  12m 2604 S  4.2  1.7   0:01.67 httpd
24536 apache    15   0 21224  12m 2604 S  4.2  1.7   0:01.71 httpd
24537 apache    15   0 21224  12m 2604 S  4.2  1.7   0:01.71 httpd
24549 apache    15   0 21224  12m 2604 S  4.2  1.7   0:00.71 httpd
24550 apache    15   0 21224  12m 2604 S  4.2  1.7   0:00.70 httpd
24552 apache    15   0 21224  12m 2604 S  4.2  1.7   0:00.71 httpd
24553 apache    15   0 21224  12m 2604 S  4.2  1.7   0:00.71 httpd
24554 apache    15   0 21224  12m 2604 S  4.2  1.7   0:00.71 httpd
24555 apache    15   0 21224  12m 2604 S  4.2  1.7   0:00.72 httpd
24556 apache    15   0 21224  12m 2604 S  4.2  1.7   0:00.71 httpd
24557 apache    15   0 21224  12m 2604 S  4.2  1.7   0:00.71 httpd
24558 apache    15   0 21224  12m 2604 S  4.2  1.7   0:00.71 httpd
24561 apache    15   0 21224  12m 2604 S  3.8  1.7   0:00.64 httpd

Apache Bench をかけた後のプロセス:

$ ps aux | grep httpd
root     24206  0.0  0.9  12908  7136 ?        Ss   14:47   0:00 /usr/local/apache2/bin/httpd -k start
root     24503  0.0  0.0   2564   656 ?        S    15:10   0:00 /usr/local/apache2/bin/rotatelogs /home/httpd/vhost/localhost/logs/error_log.%Y%m%d 86400
root     24504  0.0  0.1   2560   824 ?        S    15:10   0:00 /usr/local/apache2/bin/rotatelogs /home/httpd/vhost/localhost/logs/access_log.%Y%m%d 86400
apache   24505  0.1  1.6  21224 13120 ?        S    15:10   0:00 /usr/local/apache2/bin/httpd -k start
apache   24506  0.1  1.6  21224 13120 ?        S    15:10   0:00 /usr/local/apache2/bin/httpd -k start
apache   24509  0.1  1.6  21224 13120 ?        S    15:10   0:00 /usr/local/apache2/bin/httpd -k start
apache   24520  3.1  1.6  21224 13128 ?        S    15:11   0:01 /usr/local/apache2/bin/httpd -k start
apache   24533  0.6  1.6  21224 13116 ?        S    15:11   0:00 /usr/local/apache2/bin/httpd -k start
apache   24534  0.6  1.6  21224 13116 ?        S    15:11   0:00 /usr/local/apache2/bin/httpd -k start
apache   24535  0.6  1.6  21224 13116 ?        S    15:11   0:00 /usr/local/apache2/bin/httpd -k start
apache   24536  0.6  1.6  21224 13116 ?        S    15:12   0:00 /usr/local/apache2/bin/httpd -k start
apache   24537  0.6  1.6  21224 13116 ?        S    15:12   0:00 /usr/local/apache2/bin/httpd -k start
apache   24538  0.6  1.6  21224 13116 ?        S    15:12   0:00 /usr/local/apache2/bin/httpd -k start
suzu     24542  0.0  0.0   4980   764 pts/2    R+   15:12   0:00 grep httpd

mod_wsgi + Django で Apache Bench を 前回と同じ mod_wsgi の設定内容で行う。

mod_wsgi/VirtualHost の 設定内容:

$ cat  vhost-django_with_wsgi-1.conf
LoadModule wsgi_module        modules/mod_wsgi.so

<VirtualHost *:80 >
    ServerName localhost

    DocumentRoot /home/httpd/vhost/localhost/public

    ErrorLog  "|/usr/local/apache2/bin/rotatelogs /home/httpd/vhost/localhost/logs/error_log.%Y%m%d 86400"
    CustomLog "|/usr/local/apache2/bin/rotatelogs /home/httpd/vhost/localhost/logs/access_log.%Y%m%d 86400" combined

    DirectoryIndex index.html

    <Directory   /home/httpd/vhost/localhost/public>
      AllowOverride All
      Options All
      Order allow,deny
      Allow from all
    </Directory>

        WSGIScriptAlias / "/home/httpd/vhost/django/django_with_wsgi/apache/django.wsgi"

        <Directory   /home/httpd/vhost/django/django_with_wsgi/apache>
          Order allow,deny
          Allow from all
        </Directory>

</VirtualHost>

apache起動直後のプロセス:

$ ps aux | grep httpd
root     24206  0.0  1.0  13776  7840 ?        Ss   14:47   0:00 /usr/local/apache2/bin/httpd -k start
root     24572  0.0  0.0   2564   660 ?        S    15:16   0:00 /usr/local/apache2/bin/rotatelogs /home/httpd/vhost/localhost/logs/error_log.%Y%m%d 86400
root     24573  0.0  0.0   2560   656 ?        S    15:16   0:00 /usr/local/apache2/bin/rotatelogs /home/httpd/vhost/localhost/logs/access_log.%Y%m%d 86400
apache   24574  0.0  0.9  13776  7112 ?        S    15:16   0:00 /usr/local/apache2/bin/httpd -k start
apache   24575  0.0  0.9  13776  7112 ?        S    15:16   0:00 /usr/local/apache2/bin/httpd -k start
apache   24576  0.0  0.9  13776  7112 ?        S    15:16   0:00 /usr/local/apache2/bin/httpd -k start
apache   24577  0.0  0.9  13776  7112 ?        S    15:16   0:00 /usr/local/apache2/bin/httpd -k start
apache   24578  0.0  0.9  13776  7112 ?        S    15:16   0:00 /usr/local/apache2/bin/httpd -k start
suzu     24582  0.0  0.0   4980   752 pts/2    R+   15:16   0:00 grep httpd

Apache Bench を2回かけます。

1回目の Apache Bench:

$  ab -n 10000 -c 100  "http://localhost/hello/"
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 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


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

Document Path:          /hello/
Document Length:        35 bytes

Concurrency Level:      100
Time taken for tests:   16.207111 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      2060000 bytes
HTML transferred:       350000 bytes
Requests per second:    617.01 [#/sec] (mean)
Time per request:       162.071 [ms] (mean)
Time per request:       1.621 [ms] (mean, across all concurrent requests)
Transfer rate:          124.08 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    9  44.1      4    2309
Processing:     4  150 284.8    107    7219
Waiting:        3  137 284.8     93    7215
Total:         87  159 286.5    114    7219

Percentage of the requests served within a certain time (ms)
  50%    114
  66%    119
  75%    122
  80%    125
  90%    166
  95%    380
  98%    548
  99%   2388
 100%   7219 (longest request)

続けて2回目の Apache Bench:

$  ab -n 10000 -c 100  "http://localhost/hello/"
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 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


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

Document Path:          /hello/
Document Length:        35 bytes

Concurrency Level:      100
Time taken for tests:   11.379051 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      2060206 bytes
HTML transferred:       350035 bytes
Requests per second:    878.81 [#/sec] (mean)
Time per request:       113.791 [ms] (mean)
Time per request:       1.138 [ms] (mean, across all concurrent requests)
Transfer rate:          176.73 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    3   5.3      0     118
Processing:    22  109 114.3    103    9872
Waiting:        2   99  29.6     98    2101
Total:         22  112 114.6    106    9888

Percentage of the requests served within a certain time (ms)
  50%    106
  66%    110
  75%    114
  80%    116
  90%    123
  95%    149
  98%    194
  99%    238
 100%   9888 (longest request)

メモリ使用状況(ab 2回目の時のスナップショット):

top - 15:17:17 up 4 days, 16:36,  2 users,  load average: 4.57, 2.34, 1.54
Tasks:  98 total,  15 running,  83 sleeping,   0 stopped,   0 zombie
Cpu(s): 70.0%us, 23.5%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  6.5%si,  0.0%st
Mem:    774616k total,   764872k used,     9744k free,   102576k buffers
Swap:   491392k total,        0k used,   491392k free,   431428k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
24586 apache    16   0 22152  13m 2608 R  6.1  1.8   0:01.11 httpd
24575 apache    16   0 22152  13m 2608 R  5.6  1.8   0:01.08 httpd
24577 apache    15   0 22152  13m 2608 S  5.6  1.8   0:01.12 httpd
24587 apache    15   0 22152  13m 2608 S  5.2  1.8   0:01.20 httpd
24589 apache    16   0 22152  13m 2608 R  5.2  1.8   0:01.10 httpd
24590 apache    15   0 22152  13m 2608 S  5.2  1.8   0:01.04 httpd
24594 apache    15   0 22152  13m 2608 S  5.2  1.8   0:01.11 httpd
24595 apache    15   0 22152  13m 2608 S  5.2  1.8   0:01.17 httpd
24596 apache    16   0 22152  13m 2608 R  5.2  1.8   0:01.16 httpd
24597 apache    15   0 22152  13m 2608 S  5.2  1.8   0:01.18 httpd
24576 apache    16   0 22152  13m 2608 R  4.8  1.8   0:01.16 httpd
24578 apache    16   0 22152  13m 2608 R  4.8  1.8   0:01.10 httpd
24584 apache    16   0 22152  13m 2608 R  4.3  1.8   0:01.60 httpd
24585 apache    15   0 22152  13m 2608 S  4.3  1.8   0:01.29 httpd
24591 apache    15   0 22152  13m 2608 S  4.3  1.8   0:01.15 httpd
24592 apache    16   0 22152  13m 2608 S  4.3  1.8   0:01.12 httpd
24593 apache    15   0 22152  13m 2608 S  4.3  1.8   0:01.10 httpd
24598 apache    15   0 22152  13m 2608 R  3.5  1.8   0:01.09 httpd
24574 apache    15   0 22152  13m 2608 R  0.0  1.8   0:01.59 httpd
24601 apache    17   0 22152  13m 2600 R  0.0  1.8   0:00.23 httpd

Apache Bench をかけた後のプロセス:

$ ps aux | grep httpd
root     24206  0.0  1.0  13776  7840 ?        Ss   14:47   0:00 /usr/local/apache2/bin/httpd -k start
root     24572  0.0  0.0   2564   660 ?        S    15:16   0:00 /usr/local/apache2/bin/rotatelogs /home/httpd/vhost/localhost/logs/error_log.%Y%m%d 86400
root     24573  0.0  0.1   2560   824 ?        S    15:16   0:00 /usr/local/apache2/bin/rotatelogs /home/httpd/vhost/localhost/logs/access_log.%Y%m%d 86400
apache   24574  0.8  1.8  22152 14060 ?        S    15:16   0:01 /usr/local/apache2/bin/httpd -k start
apache   24576  0.6  1.8  22152 14060 ?        S    15:16   0:01 /usr/local/apache2/bin/httpd -k start
apache   24577  0.6  1.8  22152 14060 ?        S    15:16   0:01 /usr/local/apache2/bin/httpd -k start
apache   24578  0.6  1.8  22152 14060 ?        S    15:16   0:01 /usr/local/apache2/bin/httpd -k start
apache   24585  0.8  1.8  22152 14060 ?        S    15:16   0:01 /usr/local/apache2/bin/httpd -k start
apache   24586  0.7  1.8  22152 14060 ?        S    15:16   0:01 /usr/local/apache2/bin/httpd -k start
apache   24587  0.7  1.8  22152 14060 ?        S    15:16   0:01 /usr/local/apache2/bin/httpd -k start
apache   24590  0.6  1.8  22152 14060 ?        S    15:16   0:01 /usr/local/apache2/bin/httpd -k start
apache   24592  0.7  1.8  22152 14060 ?        S    15:16   0:01 /usr/local/apache2/bin/httpd -k start
apache   24601  0.1  1.8  22152 14048 ?        S    15:17   0:00 /usr/local/apache2/bin/httpd -k start
suzu     24607  0.0  0.0   4980   748 pts/2    R+   15:19   0:00 grep httpd

Apache Bench で使用するハードウェアのスペック と Apache Conf (httpd-mpm.conf)ファイルの内容

CPU:

$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 9
model name      : Intel(R) Pentium(R) M processor 1300MHz
stepping        : 5
cpu MHz         : 600.000
cache size      : 1024 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 2
wp              : yes
flags           : fpu vme de pse tsc msr mce cx8 mtrr pge mca cmov pat clflush dts acpi mmx fxsr sse sse2 tm pbe up est tm2
bogomips        : 1199.72

メモリー:

$ cat /proc/meminfo
MemTotal:       774616 kB
MemFree:         76940 kB
Buffers:        116240 kB
Cached:         492680 kB
SwapCached:          0 kB
Active:         365236 kB
Inactive:       273396 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:       774616 kB
LowFree:         76940 kB
SwapTotal:      491392 kB
SwapFree:       491392 kB
Dirty:               0 kB
Writeback:           0 kB
AnonPages:       29700 kB
Mapped:          20712 kB
Slab:            51360 kB
PageTables:       1488 kB
NFS_Unstable:        0 kB
Bounce:              0 kB
CommitLimit:    878700 kB
Committed_AS:   119760 kB
VmallocTotal:   245752 kB
VmallocUsed:      3476 kB
VmallocChunk:   242080 kB
HugePages_Total:     0
HugePages_Free:      0
HugePages_Rsvd:      0
Hugepagesize:     4096 kB

(2) Apache Conf (httpd-mpm.conf)ファイルの内容:

$ cat /usr/local/apache2/conf/extra/httpd-mpm.conf
<IfModule !mpm_netware_module>
    PidFile "logs/httpd.pid"
</IfModule>

<IfModule !mpm_winnt_module>
<IfModule !mpm_netware_module>
LockFile "logs/accept.lock"
</IfModule>
</IfModule>

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients           20
    MaxRequestsPerChild   0
</IfModule>

mod_wsgi + Django でもう一度 Apache Bench をかけてみます。

mod_wsgiの作者 Graham Dumpleton さんより、Apacheの設定や検証方法についてアドバイスを頂きましたので、頂いたアドバイスを元に再度検証してみたいと思います。

前回検証したハードウェアと今回は違うものを使うので、前回と同じ設定のパターンと、アドバイス頂いた設定 WSGIApplicationGroup と WSGIImportScript を使用したパターンの2つの検証をします。
それぞれのパターンで、2回づつ Apache Bench をかけます。


◆今回の記事のサマリーです。

  1. Apache Bench で使用するハードウェアのスペック と Apache Conf (httpd-mpm.conf)ファイルの内容
  2. mod_wsgi + Django で Apache Bench を 前回(※)と同じ mod_wsgi の設定内容で行う。
  3. mod_wsgi + Django で Apache Bench を ApplicationGroup と WSGIImportScript を使用た設定で行う。
  4. mod_wsgi + Django で Apache Bench の比較結果

※前回と同じ mod_wsgi の設定内容は、「Django Ver.1 + mod_wsgiで Apache Bench と メモリ使用状況を確認する。」です。

http://www.djangoproject.com/download/

$ svn co http://code.djangoproject.com/svn/django/trunk/ ~/svn/django-trunk

$ cd ~/svn/django-trunk/

$ sudo python setup.py install

$ django-admin.py --version

参考:『Django Ver.1 + mod_wsgi で "Hello, world!"

Python Ver2 インストール

http://www.python.org/
http://www.python.jp/Zope/

ダウンロード
http://www.python.jp/Zope/download/pythoncore
ftp://ftp.python.jp/ftp.python.org/
http://www.python.org/download/

$ wget http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tgz
$ tar xvzf Python-2.5.2.tgz
$ cd Python-2.5.2
$ less README
$ ./configure --help
$ ./configure
$ make
$ make test
$ ./python -V
$ ./python
$ sudo make install

$ which python

参照:『easy_install を使えるようにインストールする。


 ab - Apache HTTP server benchmarking tool
    http://www.apache.jp/manual/programs/ab.html

同時発行数を100リクエスト、10000回のアクセスを実行。
$ ab -n 10000 -c 100 
DBへのアクセスはせず、「Hello, world.」を返すぐらいだけのものでベンチマークをとります。
abコマンド実行中にtopコマンドでメモリの使用状況を確認。

◆メモリ(1プロセスあたり)

Ruby on Rails + mod_rails (mod_passenger)

Mem:    256400k total,   253792k used,     2608k free,      540k buffers
Swap:   524280k total,    18708k used,   505572k free,    21388k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 3041 suzu      25   0 45680  31m 1584 R 10.9 12.5   0:23.41 ruby
 3055 apache    15   0 12988 1888 1288 S  0.4  0.7   0:00.85 httpd

Django + mod_python
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 4207 apache    15   0 22408  14m 2272 S  8.0  5.6   0:03.64 httpd
    
Django + mod_wsgi
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 3019 apache    15   0 18072  10m 2284 S  7.0  4.0   0:05.13 httpd

Pylons + mod_wsgi
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 2915 apache    19   0 23920  14m 2568 R  0.0  5.7   0:07.15 httpd

◇結果

Ruby on Rails + mod_rails だけ、Swapを使ってしまいました。
また、Apacheのプロセスとは別に、Rubyのプロセスも必要で、メモリも消費するようにみえます。
一番メモリを消費しないのは、
Django + mod_wsgi
でした。


◆処理速度

Ruby on Rails + mod_rails (mod_passenger)
    Requests per second:    175.59 [#/sec] (mean)

Django + mod_python
    Requests per second:    576.02 [#/sec] (mean)
    
Django + mod_wsgi
    Requests per second:    854.67 [#/sec] (mean)

Pylons + mod_wsgi
    Requests per second:    380.65 [#/sec] (mean)

◇結果

秒間あたりの処理能力が一番よいのは
Django + mod_wsgi 
であり、最下位が
Ruby on Rails + mod_rails
でありました。今回の検証では、Ruby on Rails + mod_rails は、Swapを使用したため
速度比較としては、平等ではないかもしれません。

■総合結果

総合的にみても、Django + mod_wsgi が良く、Ruby on Rails + mod_rails は、最下位となりました。





Pylons Ver.0.9 + mod_wsgi で "Hello, world!" 』で用意したもので確認します。

$ cat /home/httpd/vhost/pylons/pylons_with_mod_wsgi/pylons_with_mod_wsgi/controllers/hello.py
import logging

from pylons_with_mod_wsgi.lib.base import *

log = logging.getLogger(__name__)

class HelloController(BaseController):

    def index(self):
        # Return a rendered template
        #   return render('/some/template.mako')
        # or, Return a response
        return 'Hello World. - Pylons with mod_wsgi'



$ curl http://localhost/hello/
Hello World. - Pylons with mod_wsgi

Apache Bench
$ ab -n 10000 -c 100  "http://localhost/hello/"
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 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


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

Document Path:          /hello/
Document Length:        35 bytes

Concurrency Level:      100
Time taken for tests:   26.270970 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      2990897 bytes
HTML transferred:       350105 bytes
Requests per second:    380.65 [#/sec] (mean)
Time per request:       262.710 [ms] (mean)
Time per request:       2.627 [ms] (mean, across all concurrent requests)
Transfer rate:          111.15 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    9  15.1      0      90
Processing:    50  251 165.4    230    8360
Waiting:        0  226  79.7    220    2780
Total:         90  260 166.0    240    8400

Percentage of the requests served within a certain time (ms)
  50%    240
  66%    240
  75%    250
  80%    260
  90%    280
  95%    310
  98%    760
  99%   1030
 100%   8400 (longest request)
メモリ使用状況
top - 17:29:26 up 15 min,  2 users,  load average: 16.66, 8.66, 4.29
Tasks:  62 total,  22 running,  40 sleeping,   0 stopped,   0 zombie
Cpu(s): 88.4%us,  8.7%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  2.9%si,  0.0%st
Mem:    256400k total,   253604k used,     2796k free,     3656k buffers
Swap:   524280k total,        0k used,   524280k free,    32604k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 2915 apache    19   0 23920  14m 2568 R  0.0  5.7   0:07.15 httpd
 2916 apache    19   0 23920  14m 2568 R  0.0  5.7   0:06.72 httpd
 2928 apache    19   0 23920  14m 2564 R  0.0  5.7   0:08.05 httpd
 2933 apache    19   0 23920  14m 2564 R  0.0  5.7   0:07.03 httpd
 2936 apache    19   0 23920  14m 2564 R  0.0  5.7   0:05.65 httpd
 2942 apache    19   0 23920  14m 2564 R 14.5  5.7   0:06.13 httpd
 2945 apache    19   0 23920  14m 2564 R 14.5  5.7   0:06.25 httpd
 2946 apache    19   0 23920  14m 2564 R  0.0  5.7   0:06.83 httpd
 2948 apache    19   0 23920  14m 2564 R  0.0  5.7   0:04.61 httpd
 2951 apache    19   0 23920  14m 2564 R  0.0  5.7   0:04.15 httpd
 2952 apache    19   0 23920  14m 2564 R  0.0  5.7   0:04.13 httpd
 2953 apache    19   0 23920  14m 2564 R  0.0  5.7   0:04.21 httpd
 2954 apache    19   0 23920  14m 2564 R  0.0  5.7   0:04.21 httpd
 2958 apache    19   0 23920  14m 2564 R  8.7  5.6   0:02.91 httpd
 2959 apache    19   0 23920  14m 2564 R 14.5  5.6   0:02.91 httpd
 2960 apache    19   0 23920  14m 2564 R 14.5  5.6   0:02.85 httpd
 2963 apache    19   0 23920  14m 2564 R 14.5  5.6   0:01.81 httpd
 2962 apache    19   0 23920  14m 2564 R  0.0  5.6   0:01.63 httpd
 2964 apache    19   0 23920  14m 2564 R  8.7  5.6   0:01.77 httpd
 2965 apache    19   0 23920  14m 2564 R  0.0  5.6   0:01.65 httpd

Django Ver.1 + mod_wsgi で "Hello, world!" 』で用意したもので確認します。

ApacheのConfファイル

WSGIScriptAlias / "/home/httpd/vhost/django/django_with_wsgi/apache/django.wsgi"

<Directory /home/httpd/vhost/django/django_with_wsgi/apache>
Order allow,deny
Allow from all
</Directory>
$ cat django_with_wsgi/hello/views.py
# Create your views here.
from django.http import HttpResponse

def index(request):
return HttpResponse("Hello, world. Django with mod_wsgi")

$ curl  "http://localhost/hello/"
Hello, world. Django with mod_wsgi
Apache Bench
$  ab -n 10000 -c 100   "http://localhost/hello/"
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 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


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

Document Path:          /hello/
Document Length:        35 bytes

Concurrency Level:      100
Time taken for tests:   11.700486 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      2560000 bytes
HTML transferred:       350000 bytes
Requests per second:    854.67 [#/sec] (mean)
Time per request:       117.005 [ms] (mean)
Time per request:       1.170 [ms] (mean, across all concurrent requests)
Transfer rate:          213.67 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.9      0      30
Processing:     0  116 179.9    100    4920
Waiting:        0  109 105.1    100    4290
Total:         30  116 179.9    100    4920

Percentage of the requests served within a certain time (ms)
  50%    100
  66%    100
  75%    100
  80%    100
  90%    110
  95%    120
  98%    450
  99%    670
 100%   4920 (longest request)

メモリ使用状況
top - 15:22:43 up  2:16,  2 users,  load average: 7.01, 3.76, 2.02
Tasks:  65 total,   4 running,  61 sleeping,   0 stopped,   0 zombie
Cpu(s): 81.4%us, 12.0%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  6.6%si,  0.0%st
Mem:    256400k total,   253468k used,     2932k free,     6644k buffers
Swap:   524280k total,        0k used,   524280k free,    79956k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 3019 apache    15   0 18072  10m 2284 S  7.0  4.0   0:05.13 httpd
 3058 apache    15   0 18072  10m 2284 S  6.3  4.0   0:01.54 httpd
 3006 apache    15   0 18072  10m 2284 S  5.3  4.0   0:05.14 httpd
 3054 apache    15   0 18072  10m 2284 S  5.3  4.0   0:02.11 httpd
 3055 apache    15   0 18072  10m 2284 S  5.3  4.0   0:01.66 httpd
 3060 apache    15   0 18072  10m 2284 S  5.3  4.0   0:00.64 httpd
 3031 apache    15   0 18072  10m 2284 S  5.0  4.0   0:02.85 httpd
 3026 apache    15   0 18072  10m 2284 S  4.7  4.0   0:03.48 httpd
 3050 apache    15   0 18072  10m 2284 S  4.7  4.0   0:01.85 httpd
 3023 apache    15   0 18072  10m 2284 S  4.3  4.0   0:05.07 httpd
 3033 apache    15   0 18072  10m 2284 S  4.3  4.0   0:02.89 httpd
 3041 apache    15   0 18072  10m 2284 S  4.3  4.0   0:01.95 httpd
 3044 apache    15   0 18072  10m 2284 S  4.3  4.0   0:01.98 httpd
 3056 apache    15   0 18072  10m 2284 S  4.0  4.0   0:01.67 httpd
 3038 apache    15   0 18072  10m 2284 S  3.3  4.0   0:01.89 httpd
 3048 apache    15   0 18072  10m 2284 S  3.3  4.0   0:01.73 httpd
 3052 apache    15   0 18072  10m 2284 S  3.3  4.0   0:01.88 httpd
 3049 apache    15   0 18072  10m 2284 S  3.0  4.0   0:01.85 httpd
 3053 apache    15   0 18072  10m 2284 S  3.0  4.0   0:02.03 httpd
 3047 apache    15   0 18072  10m 2284 S  2.7  4.0   0:01.75 httpd

このアーカイブについて

このページには、過去に書かれたブログ記事のうちPythonカテゴリに属しているものが含まれています。

前のカテゴリはperlです。

次のカテゴリはRuby on Railsです。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。