kafka消費報錯

問題描述:
新版本的kafka消息處理程序中,當消息量特別大時不斷出現如下錯誤,並且多個相同groupId的消費者重複消費消息。

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, 根據問題描述,處理消息的時間太長,優化消息處理(整個消息的處理時間有所減少),該告警有所減少,但是依然存在。
2,根據問題描述,將max.poll.records值設置爲200(默認值是500),並增加了session timeout(session.timeout.ms=60000, 默認值是5000,也就是5s),檢測日誌,問題有所改善,但是依然存在。

至於消息被重複消費,這是因爲發送大量消息(group.id=abc)時,consumer1消息處理時間太長,而consumer設置的是自動提交,因爲不能在默認的自動提交時間內處理完畢,所以自動提交失敗,導致kafka認爲該消息沒有消費成功,因此consumer2(group.id=abc,同一個group.id的多個消費實例)又獲得該消息開始重新消費。可以通過查看kafka中該topic對應的group的lag來驗證。

最終決絕辦法,增加auto.commit.interval.ms , 默認值是5000,增加到7000之後,同等kafka消息量下,基本沒有了該告警消息。
爲什麼修改該參數,因爲該告警的本質原因是, 消息處理時間過長,不能在設置的自動提交間隔時間內完成消息確認提交。
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章