奇怪的 Kafka 消费者组重新平衡

发布于 2025-01-09 08:28:36 字数 762 浏览 1 评论 0原文

我的 kafka 主题有两个分区和单个 kafka 消费者。我已经在 AWS 中部署了我的消费者应用程序(spring kafka)。在日志中我看到卡夫卡消费者不时地重新平衡。这种情况并不常见。根据当前的观察,当消费者正在收听主题并空闲时,会发生这种重新平衡。如果有人能向我解释这种行为,我将不胜感激。我在这里发布了一些日志。

[Consumer clientId=consumer-b2b-group-1, groupId=b2b-group] Request joining group due to: group is already rebalancing
[Consumer clientId=consumer-b2b-group-1, groupId=b2b-group] Revoke previously assigned partitions order-response-v3-qa-0, order-response-v3-qa-1
[Consumer clientId=consumer-b2b-group-1, groupId=b2b-group] Revoke previously assigned partitions order-response-v3-qa-0, order-response-v3-qa-1
b2b-group: partitions revoked: [order-response-v3-qa-0, order-response-v3-qa-1
[Consumer clientId=consumer-b2b-group-1, groupId=b2b-group] (Re-)joining group

My kafka topic has two partitions and single kafka consumer. I have deployed my consumer application(spring kafka) in the AWS. In logs I see kafka consumer re-balance in time to time. This is not frequent. As per the current observation when consumer is listening to the topic and idle this re-balancing occurs. Appreciate if someone can explain me this behavior. I have posted some logs here.

[Consumer clientId=consumer-b2b-group-1, groupId=b2b-group] Request joining group due to: group is already rebalancing
[Consumer clientId=consumer-b2b-group-1, groupId=b2b-group] Revoke previously assigned partitions order-response-v3-qa-0, order-response-v3-qa-1
[Consumer clientId=consumer-b2b-group-1, groupId=b2b-group] Revoke previously assigned partitions order-response-v3-qa-0, order-response-v3-qa-1
b2b-group: partitions revoked: [order-response-v3-qa-0, order-response-v3-qa-1
[Consumer clientId=consumer-b2b-group-1, groupId=b2b-group] (Re-)joining group

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

や莫失莫忘 2025-01-16 08:28:36

重新平衡是一项自动优化不均匀工作负载以及拓扑更改(例如添加或删除代理)的功能。这是通过后台进程实现的,该进程不断检查各种指标以确定是否以及何时应该进行重新平衡。
您可以通过以下链接获取更多知识:

https://medium.com/streamthoughts/apache-kafka-rebalance-protocol-or-the-magic-behind-your-streams-applications-e94baf68e4f2

Re-balancing is a feature that automatically optimizes uneven workloads as well as topology changes (e.g., adding or removing brokers). This is achieved via a background process that continuously checks a variety of metrics to determine if and when a to rebalance should occur.
you can go through the below link for further knowledge:

https://medium.com/streamthoughts/apache-kafka-rebalance-protocol-or-the-magic-behind-your-streams-applications-e94baf68e4f2

梦中的蝴蝶 2025-01-16 08:28:36

如果消费者加入或离开组,Kafka 就会开始重新平衡。以下是可能或将会发生这种情况的各种原因。

消费者加入组:

  1. 应用程序启动/重新启动 - 如果我们部署应用程序(或重新启动它),新的消费者会加入该组
  2. 应用程序扩展 - 我们正在创建新的 Pod/应用程序

消费者离开群组:

  1. 超过 max.poll.interval.ms — 轮询记录未及时处理
    session.timeout.ms 超出 — 没有发送心跳,可能是因为应用程序崩溃或网络错误
  2. 消费者关闭
  3. Pod 重新定位 — Kubernetes 有时会重新定位 Pod,例如,如果通过 kubectl Drain 删除节点或缩小集群规模。消费者关闭(离开组)并在另一个节点上再次重新启动(加入组)。
  4. 应用程序缩小

如果您想更深入地了解。这是我读过的一篇令人惊叹的文章

https:// medium.com/bakdata/solving-my-weird-kafka-rebalancing-problems-c05e99535435

Kafka starts a rebalancing if a consumer joins or leaves a group. Below are various reasons why that can or will happen.

A consumer joins a group:

  1. Application Start/Restart — If we deploy an application (or restart it), a new consumer joins the group
  2. Application scale-up — We are creating new pods/application

A consumer leaves a group:

  1. max.poll.interval.ms exceeded — polled records not processed in time
    session.timeout.ms exceeded — no heartbeats sent, likely because of an application crash or a network error
  2. Consumer shuts down
  3. Pod relocation — Kubernetes relocates pods sometimes, e.g. if nodes are removed via kubectl drain or the cluster is scaled down. The consumer shuts down (leaves the group) and is restarted again on another node (joins the group).
  4. Application scale-down

If you would like to understand more in depth. Here is one of the amazing article I have read

https://medium.com/bakdata/solving-my-weird-kafka-rebalancing-problems-c05e99535435

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文