Django 与 nginx +乌沃斯吉

发布于 2024-12-06 13:53:53 字数 1269 浏览 1 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

歌入人心 2024-12-13 13:53:53

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

即:

echo 3000 > /proc/sys/net/core/netdev_max_backlog
echo 3000 > /proc/sys/net/core/somaxconn

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
聚集的泪 2024-12-13 13:53:53

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文