【问题标题】:Flask/Gunicorn with 4 workers: Does long polling block a worker?Flask/Gunicorn 有 4 个工人:长轮询会阻止工人吗?
【发布时间】:2014-01-09 11:05:06
【问题描述】:

我写了这样的东西(代码更多,重要的部分是sleep(5)):

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

我这样启动我的服务器:

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

当应用程序“休眠”时,是否会阻止整个工作人员?这对gunicorn 的响应能力有何影响?

【问题讨论】:

    标签: python flask gunicorn


    【解决方案1】:

    gunicorn 将默认使用同步工作器,它一次只服务一个请求,所以 yes 将在长轮询的生命周期内消耗该工作器。 gunicorn 确实支持 asynchronous workers,这将允许工作人员在长轮询的同时处理其他请求 - 请参阅 choosing a worker type

    gunicorn -k gevent -b 127.0.0.1:8000 serve:app
    

    【讨论】:

    • 我还能用-w 4吗?
    • 是的,该页面上有关于如何设置的建议。同样相关的是--worker-connections
    • 作为记录,gunicorn 在使用异步工作线程时会自动进行猴子补丁。否则,您将不得不手动进行猴子补丁或使用gevent.sleep(5)
    • @DazWorral,您是否必须更改应用程序中的任何内容才能切换到异步?引擎盖下到底发生了什么,现在使它成为非阻塞?
    猜你喜欢
    • 1970-01-01
    • 2021-08-10
    • 2014-08-05
    • 1970-01-01
    • 1970-01-01
    • 2016-09-21
    • 1970-01-01
    • 2013-12-24
    • 2021-10-16
    相关资源
    最近更新 更多