【问题标题】:Flask gevent threads are stuck on kafka consumer烧瓶 gevent 线程卡在 kafka 消费者上
【发布时间】:2020-04-21 04:07:07
【问题描述】:

我们有一个烧瓶应用程序,在 gevent worker 模式下使用 gunicorn 进行部署。 该应用程序本身侦听少量 REST api,但也有一个 kafka 消费者(使用融合客户端)它侦听。 当我们部署应用程序时,kafka 消费者按预期工作,但是当向应用程序提交 REST 请求时,应用程序不会处理它们。

似乎应用线程卡在了 kafka 消费者身上。如果我们删除消费者代码,应用会按预期工作。

有什么建议吗?

【问题讨论】:

    标签: python flask gunicorn gevent confluent-platform


    【解决方案1】:

    问题在于我们使用 kafka 消费者的方式是“while True”

    while True:
        msg = self.client.poll(1.0)
        if msg is None:
            continue
        if msg.error():
            print("Consumer error: {}".format(msg.error()))
            continue
        self.handle_msg(msg.value())
    

    这会导致gevent 卡在上面而不是切换到其他线程。 解决方案是在消费者循环中添加一个睡眠命令,释放线程来处理 REST 请求

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-17
      • 2017-03-18
      • 2013-08-19
      • 1970-01-01
      • 2021-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多