Kafka Heartbeat详解
what does the heartbeat thread do in kafka consumer?
-
That’s all of the heartbeat thread mystery and magic. I believe we have a solid grasp of what this mechanism does and why it is important.
-
What are the key takeaways from today’s post?
-
Heartbeat thread is responsible for sending heartbeat messages to Kafka, informing about consumer liveness as well as monitoring liveness of the remote coordinator.
-
Heartbeat thread does something only when the group is stable. If it isn’t stable then thread disables itself and waits until group is stable again.
-
Heartbeats are sent every heartbeat.interval.ms
-
Maximum time for a heartbeat to be sent to prevent being evicted is session.timeout.ms
-
You have to call poll quicker than max.poll.interval.ms, otherwise your consumer will be evicted from the group.
-
Heartbeat thread is responsible for tracking aforementioned timers and timeouts
-
Be sure to close consumer after you’re finished using it, as heartbeat thread will keep it alive for a while which might result in longer rebalancing of your consumer group as coordinator’ll wait for your half-dead consumer to join.
-