Django 与 nginx +乌沃斯吉
我正在 nginx + uwsgi 上尝试 django。 它工作得很好(比 apache mod_wsgi 更快),但是如果我有超过 100 个并发连接(即:使用 ab -n 100000 -c 150 http:// /本地主机:8081/ ), 我在 uwsgi 日志上有一些损坏的管道:
nginx.conf:
user myuser;
worker_processes 8;
events {
worker_connections 30000;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream django {
ip_hash;
server unix:/home/myuser/tmp/uwsgi.sock;
}
server {
listen 8081;
server_name localhost;
location / {
uwsgi_pass django;
include uwsgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
uwsgi 是这样启动的:
/usr/local/bin/uwsgi -s /home/myuser/tmp/uwsgi.sock --pp /home/myuser/projects/django/est/nginx --module django_wsgi -L -l 500 -p 8
来自 uwsgi 的错误消息是:
writev(): Broken pipe [plugins/python/wsgi_headers.c line 206]
write(): Broken pipe [plugins/python/wsgi_subhandler.c line 235]
版本是:nginx 为 1.0.6,uwsgi 为 0.9.9.2
你知道如何解决这些错误消息吗? ?
I am trying django on nginx + uwsgi.
It works very well (faster than apache mod_wsgi), but if I have more than 100 concurrent connexion ( ie : tested with ab -n 100000 -c 150 http://localhost:8081/ ),
I have some broken pipe on uwsgi logs :
nginx.conf :
user myuser;
worker_processes 8;
events {
worker_connections 30000;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream django {
ip_hash;
server unix:/home/myuser/tmp/uwsgi.sock;
}
server {
listen 8081;
server_name localhost;
location / {
uwsgi_pass django;
include uwsgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
uwsgi is started like that :
/usr/local/bin/uwsgi -s /home/myuser/tmp/uwsgi.sock --pp /home/myuser/projects/django/est/nginx --module django_wsgi -L -l 500 -p 8
And the error messages from uwsgi are :
writev(): Broken pipe [plugins/python/wsgi_headers.c line 206]
write(): Broken pipe [plugins/python/wsgi_subhandler.c line 235]
version are : 1.0.6 for nginx and 0.9.9.2 for uwsgi
Do you know how to solve these error messages ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决方案,
问题不在uwsgi这边,有一个linux限制:套接字有128个请求长,所以要扩大等待队列,你必须调整内核:
即:
I found the solution,
The problem is not at uwsgi side, there is a linux limitation : socket are 128 request long, so to enlarge the waiting queue, you have to tune the kernel :
ie :
8 个工作线程的 150 个连接(监听队列为 100)可能是一个太高的值。也许你只需要增加监听队列。这显示在 uWSGI 主页(在基准部分下)
150 connection for 8 workers with a listen queue of 100 could be a too high value. Probably you only need to increase the listen queue. This is showed in the uWSGI homepage (under the benchmark sections)