session.timeout.ms、heartbeat.interval.ms、max.poll.interval.ms的含義及聯系


如果你使用消費者,那么一定會接觸這幾個參數:

session.timeout.ms、heartbeat.interval.ms、max.poll.interval.ms,先讓我們看看分別代表什么含義吧!
session.timeout.ms:

The timeout used to detect worker failures. The worker sends periodic heartbeats to indicate its liveness to the broker. If no heartbeats are received by the broker before the expiration of this session timeout, then the broker will remove the worker from the group and initiate a rebalance. Note that the value must be in the allowable range as configured in the broker configuration bygroup.min.session.timeout.msandgroup.max.session.timeout.ms.

名稱:會話超時時間

作用:檢測消費者是否超時故障的超時時間

機制:消費者 定期發送心跳證明自己的存活,如果在這個時間之內broker沒收到,那broker就將此消費者從group中移除,進行一次reblance。

注意:此值的配置需要在group.min.session.timeout.ms 和 group.max.session.timeout.ms 范圍內。

heartbeat.interval.ms:

The expected time between heartbeats to the consumer coordinator when using Kafka's group management facilities. Heartbeats are used to ensure that the consumer's session stays active and to facilitate rebalancing when new consumers join or leave the group. The value must be set lower thansession.timeout.ms, but typically should be set no higher than 1/3 of that value. It can be adjusted even lower to control the expected time for normal rebalances.

名稱:心跳間隔時間

作用:當消費者使用group時,用於確保消費者存活,並在消費者加入或離開group時促進reblance

注意:必須小於session.timeout.ms,但通常又不能大於session.timeout.ms的1/3,越小重新平衡的時間越短

max.poll.interval.ms:

The maximum delay between invocations of poll() when using consumer group management. This places an upper bound on the amount of time that the consumer can be idle before fetching more records. If poll() is not called before expiration of this timeout, then the consumer is considered failed and the group will rebalance in order to reassign the partitions to another member.

名稱:最大拉取間隔時間

作用:檢測消費者是否pull超時或失敗

機制:如果消費者兩次pull的時間超過了此值,那就認為此消費者能力不足,將此消費者的commit標記為失敗,並將此消費者從group移除,觸發一次reblance,將該消費者消費的分區分配給其他人。

注意:該值越大,reblance的時間越長。

所以這三個參數的目的是保證group中都是能正常消費的消費者:

1、通過心跳判斷:消費者隔heartbeat.interval.ms向broker匯報一次心跳,broker計算消費者多久沒有向自己發心跳了,如果超過了session.timeout.ms,那么就認為該消費者不可用了,將其移除。

2、通過pull()時間間隔判斷:broker如果發現max.poll.interval.ms沒有調用pull()方法,那么就將此消費者移除。

那么有同學可能會問了:如果通過心跳判斷消費者沒有死,但是通過pull超時的,那么會移除么?

雖然從0.10.1以后session.timeout.ms 和 max.poll.interval.ms 解耦了,可以在處理消息的同時發送心跳,在處理消息的時候不被移除,但是當處理完畢再次調用pull方法時發現此消費者的兩次pull是超時的,仍然會將其做失敗的重試處理,銷毀舊線程,從線程池取新線程,所以答案是會移除。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM