Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uWSGI request timeout in Python

Tags:

python

uwsgi

Trying to set the timeout for requests in uWSGI, I'm not sure of the correct setting. There seem to be multiple timeout options (socket, interface, etc.) and it's not readily evident which setting to configure or where to set it.

The behavior I'm looking for is to extend the time a request to the resource layer of a REST application can take.

like image 921
Juan Carlos Coto Avatar asked Jun 09 '14 19:06

Juan Carlos Coto


People also ask

Is uWSGI multithreaded?

If you need threads, remember to enable them with enable-threads . Running uWSGI in multithreading mode (with the threads options) will automatically enable threading support.

What does uWSGI stand for?

uWSGI (source code), pronounced "mu wiz gee", is a Web Server Gateway Interface (WSGI) server implementation that is typically used to run Python web applications.

What is Post buffering in uWSGI?

Post-buffering mode (uWSGI >= 2.0. This means that as soon as the uwsgi packet (read: the request headers) is parsed, it is forwarded to the backend/backends. Now, if your web-proxy is a streaming-one too (like apache, or the uWSGI http router), your app could be blocked for ages in case of a request with a body.

How do I enable-threads on uWSGI?

If you need threads, remember to enable them with enable-threads. Running uWSGI in multithreading mode (with the threads options) will automatically enable threading support. This “strange” default behaviour is for performance reasons, no shame in that. This is another option that might be the right choice for you.


1 Answers

You're propably looking for the harakiri parameter - if request takes longer than specified harakiri time (in seconds), the request will be dropped and the corresponding worker recycled.

For standalone uwsgi (ini config):

[uwsgi] http = 0.0.0.0:80 harakiri = 30 ... 

If you have nginx proxy before uwsgi you have to increase timeout as well:

  location / {     proxy_pass http://my_uwsgi_upstream;     proxy_read_timeout 30s;     proxy_send_timeout 30s;   } 

If you want (for some strange reason) higher timeout than 60s, you might consider communication over uwsgi protocol. Configuration is quite similar nginx site:

location / {     uwsgi_read_timeout 120s;     uwsgi_send_timeout 120s;     uwsgi_pass  my_upstream;     include     uwsgi_params; } 

uwsgi:

[uwsgi] socket = 0.0.0.0:80 protocol = uwsgi harakiri = 120 ... 
like image 132
Tombart Avatar answered Sep 21 '22 04:09

Tombart