mod_wsgi + apache 为什么不支持多线程?
WSGI 应用程序
# coding: utf-8
import time
def application(environ, start_response):
status = '200 OK'
output = str(time.time())
time.sleep(5)
output += ' -> ' + str(time.time())
response_headers = [('Content-type', 'text/html; charset=utf-8'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
Apache 虚拟主机
ServerName localhost
WSGIDaemonProcess main user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias / /var/www/main/main.wsgi
WSGIProcessGroup main
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
ErrorLog /var/log/apache2/main_error_log
CustomLog /var/log/apache2/main_log common
连接多个客户端时,它们是一个接一个地处理的,没有多线程。这是为什么呢?
2 个回答
1
虽然这不是一个直接的答案,但我注意到在一个浏览器的多个标签页中测试时,出现了串行处理的情况。(我试了chrome7和ff4)
我在想是不是浏览器强制了这种串行处理,于是我用两个不同的浏览器进行了同样的实验,结果显示服务器确实是多线程在运行。
我的设置是:
mod_wsgi 3.3-1
python 3.1.2-2
apache 2.2.17-1
在archlinux x86_64上运行
测试是在嵌入模式下使用mod_wsgi进行的。
希望这能帮到你。
3
这个问题正在mod_wsgi的邮件列表中讨论。你可以查看这里:
http://groups.google.com/group/modwsgi/browse_frm/thread/b8aaab6bfc4cca6d