Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resource temporarily unavailable using uwsgi + nginx

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.

like image 345
Nijo Avatar asked Sep 13 '25 19:09

Nijo


1 Answers

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

like image 64
Vicky Gupta Avatar answered Sep 15 '25 09:09

Vicky Gupta