jeudi 24 octobre 2019

CPU intensive route kills flask thread

I have a flask application which provides three functionalities, namely:

  1. Upload some CSV files
  2. Process the files and do very CPU intensive task
  3. Return the processed files and results.

All three are defined in app.py as:

@app.route('/upload', methods=["GET", "POST"])
def upload_file():
"""Files are uploaded"""
   ....

@app.route('/optimize', methods=["GET", "POST"])
def optimize_net():
"""Optimization done here"""
   ....

@app.route('/download', methods=["GET", "POST"])
def download():
"""Lets the user download the process files"""
   ....

And I am using gunicorn to run my app

gunicorn --bind 0.0.0.0:5000 --timeout 6000 --workers=2 wsgi:app

The problem is that the route /optimize is very compute intensive and after a while all workers go to sleep and processing stops completely.

I have checked running the same process outside of flask and everything runs fine in that case. So, I am guessing it has to do something with the min thread in flask.




Aucun commentaire:

Enregistrer un commentaire