First of all my site is up and running OK. There is no critical issues.
I want to understand a couple of things though.
I'll start with an overview of my system.
It's a django-powered site located on a CentOS 5.3 VPS with 256MB RAM, under apache with mod_wsgi.
The django application runs as a Daemon process with 1 threads.
What I need in my application is: 1. Initialize logging (currently it is working, but I get double logging every time) 2. Start to daemon threads to do some background work
Now, I have read and implemented the solution offered in http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html but it didn't help much.
Basically I had to manually disable worker MPM (only prefork MPM is running) and configure the daemon process to be with one process and one thread (for some reason it does not work with any other combination).
But what is weird is that the site is running and it is creating the 2 background threads. 1. How does that happen? 2. Does my settings mean that concurrent requests will not be handled on my site?
Here is some configuration from my site
httpd.conf
WSGIScriptAlias / /var/www/NiceHouse/trunk/apache/django.wsgi
WSGISocketPrefix run/wsgi
<VirtualHost *:80>
WSGIDaemonProcess site-1 user=**** group=**** threads=1
WSGIProcessGroup site-1
ServerName *****
ServerAlias *****
ServerAdmin *****
#DocumentRoot /usr/local/www/documents
#Alias /robots.txt /usr/local/www/documents/robots.txt
#Alias /favicon.ico /usr/local/www/documents/favicon.ico
Alias /media/ /usr/lib/python2.4/site-packages/django/contrib/admin/media/
Alias /site_media/ /var/www/NiceHouse/trunk/media/
Alias /phpmyadmin /var/www/phpmyadmin/
#<Directory /usr/local/www/documents>
#Order allow,deny
#Allow from all
#</Directory>
WSGIScriptAlias / /var/www/NiceHouse/trunk/apache/django.wsgi
#<Directory /usr/local/www/wsgi-scripts>
#Order allow,deny
#Allow from all
#</Directory>
</VirtualHost>
swtune.conf
<IfModu开发者_运维技巧le prefork.c>
StartServers 1
MinSpareServers 1
MaxSpareServers 3
ServerLimit 50
MaxClients 50
MaxRequestsPerChild 1000
</IfModule>
django.wsgi
import sys
import os
os.environ['PYTHON_EGG_CACHE']='/tmp/hoge'
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
sys.path.insert(0,'/var/www/NiceHouse/trunk')
import settings
import django.core.management
django.core.management.setup_environ(settings)
utility = django.core.management.ManagementUtility()
command = utility.fetch_command('runserver')
command.validate()
import django.conf
import django.utils
django.utils.translation.activate(django.conf.settings.LANGUAGE_CODE)
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I'll appreciate any help
Thanks, Elad
You may be getting double logging for a number of reasons. First is where have you put the logging? If you have stuck logging in settings.py file, then it will get executed twice with that WSGI script file contents you are using. The blog post explains how settings file is imported twice.
BTW, you didn't even copy the WSGI script file correctly. That in the blog post does not set DJANGO_SETTINGS_MODULE environment variable.
You may also be seeing double logging if you yourself are importing a module with the logging in it via two different paths. That is, qualified and not qualified by site package name. From memory this problem is also mention in blog post.
In respect of background threads, although you have specified threads=1, mod_wsgi has a few separate threads of its own to make sure things are working correctly and kill off process if deemed it is dead locked.
BTW, you really should get worker MPM going if you aren't using mod_php. You are only going to waste memory by using prefork MPM.
精彩评论