簡體   English   中英

Kafka拋出“ org.apache.kafka.clients.consumer.CommitFailedException”

[英]Kafka throwing “org.apache.kafka.clients.consumer.CommitFailedException”

我已經使用spring-kafka庫開發了Kafka使用者應用程序,並使用了默認的使用者配置和手動提交。

我正在運行兩個應用程序實例,它們偵聽兩個不同的Kafka主題。 在執行負載測試時,我觀察到只有一個更高負載的應用程序出現錯誤:

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.


org.apache.kafka.clients.consumer.CommitFailedException: 
    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.
    \n org.apache.kafka.clients.consumer.internals.ConsumerCoordinator.sendOffsetCommitRequest(ConsumerCoordinator.java:725)

我閱讀了幾篇文章,發現如果消費者花大量時間在處理消息和經紀人上沒有獲得有關消費者生機的信息,那么就會發生消費者重新平衡,並且對於未提交的消息將引發異常。

我已通過將max.poll.interval.ms設置為INEGER.MAX_VALUE解決了以上錯誤。 但是我想知道為什么我僅在其中一個實例中遇到錯誤,以及為什么其他實例在更高的負載下能夠正常工作。

任何人max.poll.interval.ms分享正確的根本原因和理想值,或針對此問題的適當解決方案

原因之一可能是您的poll()接收了大量消息,這就是為什么要花費大量時間來處理所有消息的原因。
max.poll.records定義在對poll()的單次調用中返回的最大記錄數。
根據kafka文檔 ,默認值為500。
您可以嘗試將其設置為較小的值,然后查看是否可以解決您的問題。

除了Yoav的建議外,如果不建議減小批量大小,還可以嘗試增加max.poll.interval.ms的值。 從Kafka文檔中:

使用使用者組管理時,調用poll()之間的最大延遲。 這為使用者在獲取更多記錄之前可以處於空閑狀態的時間設置了上限。 如果在此超時到期前未調用poll(),則認為使用方失敗,該組將重新平衡以將分區重新分配給另一個成員。

在以下屬性中將max.poll.interval.ms設置為至少5000000

consumer.set("max.poll.interval.ms","5000000");
consumer.set("max.poll.records","2");
consumer.set("session.time.out.ms","30000"); 
consumer.set("heartbeat.interval.ms","25000");

希望:-對您有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM