Django WSGI daemon mode synchronization of requests
Running appache2 with the following /etc/httpd.conf:
<VirtualHost *:80>
WSGIDaemonProcess myapp user=pq group=pq processes=2 threads=1
WSGIProcessGroup myapp
LogLevel debug
<Directory /django/myapp/apache/>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /django/myapp/apache/django.wsgi
</VirtualHost>
where this is my /django/myapp/apache/django.wsgi:
import os
import sys
sys.path.append('/django')
os.environ['PYTHONPATH'] = '/django'
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I have the following view:
def sleep(request):
print >> sys.stderr, '{', os.getpid()
time.sleep(5)
print >> sys.stderr, '}', os.getpid()
return index(request)
I make 4 concurrent requests and my error log shows:
[Wed Jan 12 12:59:56 2011] [error] {17160
[Wed Jan 12 13:00:01 2011] [error] }17160
[Wed Jan 12 13:00:01 2011] [error] {17157
[Wed Jan 12 13:00:06 2011] [error] }17157
[Wed Jan 12 13:00:06 2011] [error] {17160
[Wed Jan 12 13:00:11 2011] [error] }17160
[W开发者_高级运维ed Jan 12 13:00:11 2011] [error] {17157
[Wed Jan 12 13:00:16 2011] [error] }17157
Basically my requests were synchronized per webserver (not even per process).
Why is this?
Edit: This is a single CPU machine and Apache2 is compiled with prefork MMP. My client was 4 tabs in Chrome. Interesting, when I try this with curl I get the expected:
[Wed Jan 12 18:10:18 2011] [error] {17160
[Wed Jan 12 18:10:18 2011] [error] {17157
[Wed Jan 12 18:10:23 2011] [error] }17160
[Wed Jan 12 18:10:23 2011] [error] {17160
[Wed Jan 12 18:10:23 2011] [error] }17157
[Wed Jan 12 18:10:23 2011] [error] {17157
[Wed Jan 12 18:10:28 2011] [error] }17160
[Wed Jan 12 18:10:28 2011] [error] }17157
Edit2: Looks like this is an issue with Chrome synchronizing requests. My (limited) tests showed that this only happens with Chrome and only when tabs are used. Multiple requests within a single tab are asynchronous.
精彩评论