Question

Flask application with gunicorn in the app platform does not work

Posted January 20, 2021 179 views
PythonDigitalOcean App PlatformFlask

I have a flask application that I am trying to run in the app of platforms with a gunicorn.

wsgi.py

from app import create_app

app = create_app()


if __name__ == '__main__':
    app.run()

gconfig.py

from multiprocessing import cpu_count

bind = '0.0.0.0:8080'

workers = (2 * cpu_count()) + 1
worker_class = 'gevent'
worker_connections = 1000

timeout = 60

Run Command

gunicorn --worker-tmp-dir /dev/shm -c gconfig.py wsgi:app

After the build in the logs:

app-name | 2021-01-20 15:24:25 [2021-01-20 13:24:25 +0000] [1] [INFO] Starting gunicorn 20.0.4
app-name | 2021-01-20 15:24:25 [2021-01-20 13:24:25 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
app-name | 2021-01-20 15:24:25 [2021-01-20 13:24:25 +0000] [1] [INFO] Using worker: gevent
app-name | 2021-01-20 15:24:25 [2021-01-20 13:24:25 +0000] [11] [INFO] Booting worker with pid: 11
app-name | 2021-01-20 15:24:25 [2021-01-20 13:24:25 +0000] [12] [INFO] Booting worker with pid: 12
app-name | 2021-01-20 15:24:25 [2021-01-20 13:24:25 +0000] [13] [INFO] Booting worker with pid: 13
app-name | 2021-01-20 15:24:25 [2021-01-20 13:24:25 +0000] [14] [INFO] Booting worker with pid: 14
app-name | 2021-01-20 15:24:26 [2021-01-20 13:24:25 +0000] [15] [INFO] Booting worker with pid: 15
app-name | 2021-01-20 15:24:26 [2021-01-20 13:24:26 +0000] [16] [INFO] Booting worker with pid: 16
app-name | 2021-01-20 15:24:26 [2021-01-20 13:24:26 +0000] [17] [INFO] Booting worker with pid: 17
app-name | 2021-01-20 15:24:26 [2021-01-20 13:24:26 +0000] [18] [INFO] Booting worker with pid: 18
app-name | 2021-01-20 15:24:27 [2021-01-20 13:24:27 +0000] [19] [INFO] Booting worker with pid: 19
app-name | 2021-01-20 15:24:27 [2021-01-20 13:24:27 +0000] [20] [INFO] Booting worker with pid: 20
app-name | 2021-01-20 15:24:28 [2021-01-20 13:24:28 +0000] [21] [INFO] Booting worker with pid: 21
app-name | 2021-01-20 15:24:29 [2021-01-20 13:24:28 +0000] [22] [INFO] Booting worker with pid: 22
app-name | 2021-01-20 15:24:29 [2021-01-20 13:24:29 +0000] [23] [INFO] Booting worker with pid: 23
app-name | 2021-01-20 15:24:30 [2021-01-20 13:24:30 +0000] [24] [INFO] Booting worker with pid: 24
app-name | 2021-01-20 15:24:30 [2021-01-20 13:24:30 +0000] [25] [INFO] Booting worker with pid: 25
app-name | 2021-01-20 15:24:31 [2021-01-20 13:24:31 +0000] [26] [INFO] Booting worker with pid: 26
app-name | 2021-01-20 15:24:32 [2021-01-20 13:24:32 +0000] [27] [INFO] Booting worker with pid: 27

When I go to the url, then in the browser I just have the text:

no healthy upstream
edited by kamaln7

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

That configuration looks reasonable. Without seeing the application, this advice is just speculation. The App Platform does health checks against the http port specified for the application at deployment. If the app is getting past those, and then you’re seeing “no healthy upstreams” the application may be crashing after boot. This could be caused by exceeding memory limits for the application, by an internal error in the application, or more rarely by an error in our system. I’d recommend trying a larger instance size, and if you’re still seeing trouble contact support. Our support team (with your permission) can examine your running application to see if there’s anything we can see from our end.

  • Yes, I figured out the problem, most likely the application did not start due to the limits.

    This is very strange, but for some reason the system determines that it has 8 cpu.

    >>> from multiprocessing import cpu_count
    >>> cpu_count()
    8
    

    I don’t like hardcode, but I had to manually setup 3 workers for the gunicorn and everything works.
    I just would like to know what is the reason.

Submit an Answer