5

I have a Nginx+Gunicorn+Flask application which provides some APIs using a machine learning model. The model is stored in a large file and takes long time (about one minute) to be loaded into memory. Now I want to update the model file and restart the worker without downtime. How can I configure gunicorn (or something) to wait until new processes load?

Just sending kill -HUP seems to be insufficient for the purpose. Requests which come before the new process loads seems to be dropped.

meirin
  • 51
  • 3

2 Answers2

2

gunicorn has a argument:

-t, --timeout.

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

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Peng Liu
  • 51
  • 5
0

Sometimes, for me when there is a compute intensive workload in the server, gunicorn restart takes a lot of time to restart.

This gets the ports of gunicorn and kills the workers right away.

sudo kill -9 `sudo lsof -n -i | grep gunicorn | awk '{print $2}'`

and then restart

sudo service gunicorn restart
SuperNova
  • 25,512
  • 7
  • 93
  • 64