在使用了最新版的 kafka-python 1.4.7 在 broker 对 topic 进行默认配置的情况下报出类似错误
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 loopisspending too much
time message processing. You can addressthiseither by
increasing the rebalance timeout with max_poll_interval_ms,
or by reducing the maximum size of batches returnedinpoll()
with max_poll_records.
这里要申明一点,在 1.4.0 以上的 kafka-python 版本使用了独立的心跳线程去上报心跳。
这里报错大概表达的意思是 无法在默认 300000ms 中完成处理操作。我们通常会一次性 poll 拉默认 500 条数据下来。我们需要在 300s 中完成 500 条数据的处理。如果不能完成的话就可能会触发这个问题。
因为这个报错的提示写得非常清楚,所以我们先按这个方向去尝试处理这个问题。首先调高了我们的 max_poll_interval_ms 的时间,但是无效。
然后 records 的条数减少,依然无效,该报错还是会报错。这不禁让我怀疑触发这个问题的是否并非这里报错建议的那些地方。
所以我把目前放到了 broker 日志那边去,想看下到底是因为什么原因导致爆出类似错误。
在日志上发现了一些日志,对应的 consumer 在反复的 rebalance:
[2019-08-18 09:19:29,556] INFO [GroupCoordinator 0]: Member kafka-python-1.4.6-05ed83f1-aa90-4950-b097-4cf467598082 in group sync_group_20180321 has fa