繁体   English   中英

在 python kafka 消费者中获取 CommitFailedError

[英]Getting CommitFailedError in python kafka consumer

我使用以下配置在 python 中创建了 Kafka 消费者。

 consumer = KafkaConsumer(topic, 
                          group_id='consumer', 
                          bootstrap_servers=[bootstrap_servers], 
                          auto_offset_reset='latest', 
                          value_deserializer=lambda m:json.loads(m.decode('utf-8')), 
                          max_poll_records=1, 
                          max_poll_interval_ms=900000)

每条记录的处理时间约为 10 分钟,小于max_poll_interval_ms (15 分钟)。即使在更高的max_poll_interval_ms值之后,每当调用 consumer.commit() 时,我都会遇到异常

kafka.errors.CommitFailedError: CommitFailedError: Commit cannot be completed since the group has already
            rebalanced and assigned the partitions to another member.
            This means that the time between subsequent calls to poll()
            was longer than the configured max_poll_interval_ms, which
            typically implies that the poll loop is spending too much
            time message processing. You can address this either by
            increasing the rebalance timeout with max_poll_interval_ms,
            or by reducing the maximum size of batches returned in poll()
            with max_poll_records

我无法弄清楚为什么它失败了,有人可以在这里帮忙吗?

您能否确认您在什么时间点提交抵消? 您是在使用任何一种提交 API(同步/异步)还是只是设置自动提交属性,例如 enable.auto.commit = true auto.commit.interval.ms。 因为,这些参数是使消费者提交成功或失败的关键参数。 此外,最好了解 session.timeout.ms 的行为,您的问题的解决方案就在这里。

session.timeout.ms

消费者在仍然被认为处于活动状态的情况下可以与经纪人失去联系的时间默认为 3 秒。 如果超过 session.timeout.ms 没有消费者向组协调器发送心跳,则认为它已死,组协调器将触发消费者组的重新平衡以将分区从死的消费者分配给组中的其他消费者. 该属性与 heartbeat.interval.ms 密切相关。 heartbeat.interval.ms 控制 KafkaConsumer poll() 方法向组协调器发送心跳的频率,而 session.timeout.ms 控制消费者可以在多长时间内不发送心跳。 因此,这两个属性通常一起修改——heatbeat.interval.ms 必须低于 session.timeout.ms,并且通常设置为超时值的三分之一。 所以如果 session.timeout.ms 是 3 秒,heartbeat.interval.ms 应该是 1 秒。 将 session.timeout.ms 设置为低于默认值将允许使用者组更快地检测到故障并从故障中恢复,但也可能由于使用者花费更长的时间来完成轮询循环或垃圾收集而导致不必要的重新平衡。 将 session.timeout.ms 设置得更高会减少意外重新平衡的机会,但也意味着检测真正的故障需要更长的时间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM