Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask/Gunicorn with 4 workers: Does long polling block a worker?

I wrote something like this (with more code, the important part is the sleep(5)):

def get(self):
    import time
    time.sleep(5)
    return jsonify({'result':'OK'})

I start my server like this:

gunicorn serve:app -b 127.0.0.2:8000 -w 4

While the app is "sleeping" is that blocking a whole worker? How does this affect gunicorn's ability to respond?

like image 492
Johnston Avatar asked Jan 09 '14 11:01

Johnston


1 Answers

gunicorn will default to using synchronous workers, which will only serve one request at a time, so yes will consume that worker for the lifetime of the long poll. gunicorn does support asynchronous workers, which will allow a worker to serve other requests along side the long poll - see choosing a worker type:

gunicorn -k gevent -b 127.0.0.1:8000 serve:app
like image 122
DazWorrall Avatar answered Sep 25 '22 10:09

DazWorrall