Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure different timeouts in gunicorn for different endpoints?

Tags:

Gunicorn allows configuring a timeout for requests, as demonstrated in their documentation below. This seems to be a global configuration for the entire application.

Is it possible to configure different timeouts for different endpoints? Perhaps overriding the default timeout on url endpoints that are known to take a long time?

http://docs.gunicorn.org/en/stable/settings.html#timeout

timeout

-t INT, --timeout INT

30

Workers silent for more than this many seconds are killed and restarted.

Generally set to thirty seconds. Only set this noticeably higher if you’re sure of the repercussions for sync workers. For the non sync workers it just means that the worker process is still communicating and is not tied to the length of time required to handle a single request.

like image 232
Ben Harrison Avatar asked Jul 20 '17 16:07

Ben Harrison


People also ask

What is gunicorn default timeout?

By default, Gunicorn gracefully restarts a worker if hasn't completed any work within the last 30 seconds. If you expect your application to respond quickly to constant incoming flow of requests, try experimenting with a lower timeout configuration.

Where does gunicorn log by default?

This log file is located at /var/log/cloudify/rest/gunicorn-access.

How do I enable gunicorn?

Runit. Save this as /etc/sv/[app_name]/run , and make it executable ( chmod u+x /etc/sv/[app_name]/run ). Then run ln -s /etc/sv/[app_name] /etc/service/[app_name] . If runit is installed, Gunicorn should start running automatically as soon as you create the symlink.


1 Answers

There is no easy way to do what you want to do. Probably the best option is to package each endpoint into a separate application, and then launch them with their own separate gunicorn processes / workers with the appropriate timeouts. Then put something like nginx to proxy the endpoints to different gunicorn processes.

like image 98
Adam Avatar answered Jan 21 '23 21:01

Adam