Django Projectãéçºãµã¼ãã¼ã®ä½¿ãå¿å°ã®ã¾ã¾ã«Apacheã§ãããã¤ãã
ãã¼ã£ã¨ããããã¤ãè¦æã ã£ãã
èªåã§ããã¨å
¨ç¶åããäºãç¡ãã
ã§ãæ°ã¥ãã°ããã¤ã®éã«ãåºæ¥ãæ§ã«ãªã£ã¦ãã
ä»å¾å¿ãã¦ãã¾ããªãããã«ã¡ã¢ã
æ¨æ¥ä½ã£ãç°å¢ã§ãããã¤ãè¡ãã
æ©è½çãªã¨ãã
ä¸æºå
ä½æããDjangoã®ããã¸ã§ã¯ãã¯ãdjangoProjectã
- /var/wwwå ã«ãããã¸ã§ã¯ãã¨.wsgiãã¡ã¤ã«ãå ¬éãããã£ã¬ã¯ããªï¼django)ãä½æããã
- ããã¸ã§ã¯ãã®ã½ã¼ã¹ãå±éããï¼å®éã¯ãã¼ã«ã«ãªãããã®ãªã³ã¯ï¼
- /var/www/django/djangoProject
- ã¢ããªã±ã¼ã·ã§ã³åã¯ä»¥ä¸ã®éã
- djangoProject.core
- wsgiã®èªååèµ·åç¨ã®ã¹ã¯ãªãããããã¸ã§ã¯ãå
ã«ä½æããã
- http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Monitoring_For_Code_Changes
- ä¸è¨URLã«ã®ã£ã¦ããã³ã¼ããmonitor.pyã¨è¨ãååã§ãcoreã¢ããªå ã«ä¿åãã
apacheã®è¨å®
è¨å®å
ã¯ã/etc/apache2/conf.d/ã¨/var/www/ ã®äºã¶æ
ããããã«ãã¡ã¤ã«ãä¸ã¤ãã¤ä½æããã
- /etc/apache2/conf.d/djangoProject.conf
WSGIScriptAlias / /var/www/django/djangoProject.wsgi
Order deny,allow
Allow from all
Alias /static "/var/www/django/djangoProject/static"
Order deny,allow
Allow from all
Alias /media "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/contrib/admin/media"
Options All
AllowOverride All
Allow from All
- /var/www/django/djangoProject.wsgi
import os, sys
sys.path.append('/var/www/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'djangoProject.settings'from djangoProject.core import monitor
monitor.start(interval=3.0)import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Pathéããªãã¨monitor.pyãã¤ã³ãã¼ãåºæ¥ãªãã£ãã
ãã¡ã¤ã«ã®æ´æ°ãã§ãã¯ã¯3ç§æ¯ã«ãã¦ãããã©ã0.1ç§ã¨ãã«ãåºæ¥ãã¯ã
ãã³ããã¦ã¿ã
id:everesããã«ãæ®éã«ãããã¤ããªãã¨è¨ãããã®ã§ãããä¸ã®ããæ¹ã§æ®éã«ãããã¤ã«ãªãã®ã§ããããï¼å¿é ã
ã¨ãããã¥ãåªåã¯é ¬ãããã®ãéçºãµã¼ãã¨Apache+mod_wsgiãæ¯è¼ãã¦ã¿ãã
- ab -n 1000 http://127.0.0.1/get/csv
serv | requests | concurrensy | [#/sec] |
manage.py | 1000 | æå®ç¡ | 631.67 |
apache | 1000 | æå®ç¡ | 617.97 |
ããã¾ãéããªã£ã¦ãªããã
ãã£ã¦ããããããé
ãã»ã»
æ²ããããã
以åã¯ãconcurrensyå¢ããã¨å
¨ç¶ãã¡ãã¡ã«ãªã£ã¦ãã£ãã®ã§ -cä»ãã§ãã¹ãç¶è¡
- ab -n 1000 -c 40 http://127.0.0.1/get/csv
serv | requests | concurrensy | [#/sec] |
manage.py | 1000 | 50 | 345.38 |
apache | 1000 | 50 | 598.64 |
Apacheã®æ¹ã¯ãããã¾ãæ§è½è½ã¡ã¦ãªããç´ æ´ãããããã¹ãæ¯ã«å¤å°ã®ãã©ããã¯ãããã©å®å®ãã¦ããã
éçºãµãã®æ¹ã¯ããã¹ãæ¯ã«æ§è½ã®ãã©ãããå¤ããããåã«ãã£ã¦ã¯ãã¨ã©ã¼å¤ããã§abãéä¸ã§ãã¹ãæ¢ããããããããã«ä¸åä¸èª¿ã«ãªãã¨ããã®å¾ãã°ããä¸èª¿ãç¶ããããã¦ãéçºãµã¼ãåèµ·åããªãã¨èª¿åãæ»ããªãã£ããããã
使ããªãæã¯ãªããªï¼apache + mod_wsgi + èªåãªãã¼ã
ããããªãã¦ããåãäºä½åããã£ã¦ãã¨ãã¤ã®éã«ãç解ã§ããæ°ãããã®ã¯ãªãã§ã ããï¼åé¡ããã£ãããã¨ãããã¥ãtailã³ãã³ãã«-fã¤ãã¦
# tail -f /var/log/apache2/error.log
ãã®ããæ¹ãè¦ã¤ãã¦ããã®æè¿ãã®æ©ãã¯ç°å¸¸ã
apacheã«ãããã¤ãã¦ãèªåã§åèµ·åãã¦ããããªããããéçºãµã¼ããããªãããããªããã¨æãã
åé¡ã¨ãæ°ã¥ããäºãªã©
- print ãå ¥ã£ã¦ãã¨æãããã®ã§ãããè¥å¹²é¢åããããloggingã¢ã¸ã¥ã¼ã«ãç©æ¥µçã«ä½¿ã£ã¦ããããã
- DBã¯ãsqlite使ã£ã¦ããããªã®ãããã¼ããã·ã§ã³ã§æããã ï¼ apacheãèªåã§èµ·åããããã«æ¸ãæããï¼å¤åãã£ã¡ããããªããã ãããªãã»ã»ï¼
- ADMIN_MEDIAã®æã£ã¦ãæ¹ããããªç´æ¥çãªæå®ã®ä»æ¹ã§ããã®ããª?
- NGINXã®æ¹ãè¨å®æ¥½ãããªãã§ããã©ã»ã»ã»
- memcachedãä½µãã¦èµ·åç管çããããã©ãããæ¹åããã