kafka消费报错
問題描述:
新版本的kafka消息處理程序中,當(dāng)消息量特別大時不斷出現(xiàn)如下錯誤,并且多個相同groupId的消費(fèi)者重復(fù)消費(fèi)消息。
2018-10-12 19:49:34,903 WARN [DESKTOP-8S2E5H7 id2-1-C-1] Caller+0 at org.apache.kafka.clients.consumer.internals.ConsumerCoordinator$4.onComplete(ConsumerCoordinator.java:649)
Auto-commit of offsets {xxxTopic-5=OffsetAndMetadata{offset=359, metadata=’’}} failed for group My-Group-Name: 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 session timeout or by reducing the maximum size of batches returned in poll() with max.poll.records.
解決辦法:
分析:
1, 根據(jù)問題描述,處理消息的時間太長,優(yōu)化消息處理(整個消息的處理時間有所減少),該告警有所減少,但是依然存在。
2,根據(jù)問題描述,將max.poll.records值設(shè)置為200(默認(rèn)值是500),并增加了session timeout(session.timeout.ms=60000, 默認(rèn)值是5000,也就是5s),檢測日志,問題有所改善,但是依然存在。
至于消息被重復(fù)消費(fèi),這是因為發(fā)送大量消息(group.id=abc)時,consumer1消息處理時間太長,而consumer設(shè)置的是自動提交,因為不能在默認(rèn)的自動提交時間內(nèi)處理完畢,所以自動提交失敗,導(dǎo)致kafka認(rèn)為該消息沒有消費(fèi)成功,因此consumer2(group.id=abc,同一個group.id的多個消費(fèi)實(shí)例)又獲得該消息開始重新消費(fèi)。可以通過查看kafka中該topic對應(yīng)的group的lag來驗證。
最終決絕辦法,增加auto.commit.interval.ms , 默認(rèn)值是5000,增加到7000之后,同等kafka消息量下,基本沒有了該告警消息。
為什么修改該參數(shù),因為該告警的本質(zhì)原因是, 消息處理時間過長,不能在設(shè)置的自動提交間隔時間內(nèi)完成消息確認(rèn)提交。
?
總結(jié)
- 上一篇: skywalking告警相关配置
- 下一篇: go 安装墙外的依赖包报错问题