P
P
Pavel Dyukarev2017-07-22 14:18:28
Django
Pavel Dyukarev, 2017-07-22 14:18:28

How to set response timeout in gunicorn?

Guys, need help!) Deployed Django app on Heroku. Everything works except for one. My application performs the function of parsing a group conversation on Vkontakte: it downloads the entire history of correspondence to a file and counts the number of messages from each participant.
The analysis function itself in Dzhang takes a long time - about 45 seconds. This is superimposed by a large volume of correspondence and a limitation of requests per second of the Vkontakte API. So when I call the Janga view responsible for parsing, it only returns a response after 45-50 seconds.
(I will only get to Channels in a month, so I can’t run the function in a separate worker now - I need to grow.)
As a result, Gunicorn, if there is no response from the Janga server within 30 seconds, returns Request timeout. Here are the logs from Heroku:

2017-07-22T11:05:14.860483+00:00 heroku[router]: at=error code=H12 desc="<b>Request timeout</b>" method=GET path="/update/" host=vki141b.herokuapp.com request_id=9a53ee89-bae3-4ee0-92a5-f8265c8d5e0e fwd="94.25.180.161" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
2017-07-22T11:05:14.871450+00:00 app[web.1]: [2017-07-22 11:05:14 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:9)
2017-07-22T11:05:14.871946+00:00 app[web.1]: [2017-07-22 11:05:14 +0000] [9] [INFO] Worker exiting (pid: 9)
2017-07-22T11:05:14.951888+00:00 app[web.1]: [2017-07-22 11:05:14 +0000] [16] [INFO] Booting worker with pid: 16

This is where I need help! I'm trying to change the wait value to a larger one, but it doesn't work.
Here is Heroku's instructions on how to do this.
In the console I type the following: $ gunicorn statistic:app --timeout 120
The command returns the following:
Failed to find application: 'statistic'
[2017-07-22 14:10:25 +0300] [9138] [INFO] Worker exiting (pid: 9138)
[2017-07-22 14:10:25 +0300] [9135] [INFO] Shutting down: Master
[2017-07-22 14:10:25 +0300] [9135] [INFO] Reason: App failed to load.

Gunicorn refuses to see my statistic app. You need to make him see (my love).
I did not find a solution to this problem. There are similar questions on Stackoverflow, but they didn't help me personally.
Here you can see my broken application. The error gets out if you click on the "Update" button.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Tiunov, 2017-07-22
@PavelDuk

docs.gunicorn.org/en/stable/run.html#django
In your project, next to settings.py, there should be a wsgi.py file with something like this:

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

And then Gunicorn is launched with the command:
*project is the directory where settings.py is located, you may have a different structure.
**-c gunicorn.conf.py is a link to the configuration file, the timeout can be set through arguments, or in this file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question