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