Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django with nginx + uwsgi

Tags:

nginx

uwsgi

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 ?

like image 699
Eric Avatar asked Sep 26 '11 15:09

Eric


People also ask

Is Nginx needed with uWSGI?

Can I then ditch NGINX? uWSGI could be used as a standalone web server in production, but that is not it's intentional use. It may sound odd, but uWSGI was always supposed to be a go-between a full-featured web server like NGINX and your Python files.


2 Answers

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 :

echo 3000 > /proc/sys/net/core/netdev_max_backlog
echo 3000 > /proc/sys/net/core/somaxconn
like image 73
Eric Avatar answered Oct 09 '22 17:10

Eric


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)

like image 38
roberto Avatar answered Oct 09 '22 18:10

roberto