Nginx/uwsgi request buffer or queue

nginxuwsgi

Our web servers run a Python app behind nginx + uwsgi.

Sometimes we have short spikes (2-5x avg no requests) for a second resulting in some requests getting a 502 if there are no workers available to handle them.

Is there a way for nginx or uwsgi to queue these requests up and serve them when workers become available?

It's better with a short increase in response time rather than getting an error 😉

Best Answer

There is no way for nginx to do that. Directive queue is available as part of Nginx commercial subscription only. https://nginx.ru/en/docs/http/ngx_http_upstream_module.html#queue

A good decision is run several (2 or more) uwsgi backends with nginx uwsgi_next_upstream directive https://nginx.ru/en/docs/http/ngx_http_uwsgi_module.html#uwsgi_next_upstream.

Also you can try error_page 502 =307 http://backup.example.com/;