I've django app host using nignx-uwsgi. Here is my uwsgi configuration:
[uwsgi]
master = true
socket = /var/uwsgi/uwsgi.sock
chmod-socket = 666
chdir = /home/ubuntu/test
wsgi-file = /home/ubuntu/test/test/wsgi.py
virtualenv = /home/ubuntu/virtual
vacuum = true
enable-threads = true
daemonize= /home/ubuntu/uwsgi.log
I'm getting error in nignx log
2017/06/16 04:25:42 [error] 26129#0: *1141328 connect() to unix:///var/uwsgi/uwsgi.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: xxx.xxx.xx, server:
and the site shows 502 bad gateway. I have to restart uwsgi to fix it. But the frequency of the error is increasing. Is there anyway to fix this.
This error comes when there is a heavy load on the server. First I had tried by increasing the value of worker_connections but it didn't work. Queue size for uWSGI is by default 100, so when more than 100 requests from Nginx to uWSGI is passed, queue get full and Nginx throws 502 to the client, to solve this increase the queue size of uWSGI. In uwsgi.ini file add "listen= {required queue size} ". In my case, I wrote, listen=200.
But before doing it, you must check $ cat /proc/sys/net/core/somaxconn
by default it's value is 128, so increase its vale by:
$echo 200 > /proc/sys/net/core/somaxconn
or $ sysctl -w net.core.somaxconn=200
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With