django与nginx + uwsgi

Eri*_*ric 12 nginx uwsgi

我在nginx + uwsgi上尝试django.它工作得很好(比apache mod_wsgi快),但是如果我有超过100个并发连接(即:用ab -n 100000 -c 150 http:// localhost: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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

来自uwsgi的错误消息是:

writev(): Broken pipe [plugins/python/wsgi_headers.c line 206]
write(): Broken pipe [plugins/python/wsgi_subhandler.c line 235]
Run Code Online (Sandbox Code Playgroud)

版本是:nginx为1.0.6,uwsgi为0.9.9.2

你知道如何解决这些错误信息吗?

Eri*_*ric 8

我找到了解决方案,问题不在uwsgi端,有一个linux限制:socket是128请求长,所以要扩大等待队列,你必须调整内核:

即:

echo 3000 > /proc/sys/net/core/netdev_max_backlog
echo 3000 > /proc/sys/net/core/somaxconn
Run Code Online (Sandbox Code Playgroud)