Skip to content

Commit

Permalink
improve(docs): add article content
Browse files Browse the repository at this point in the history
  • Loading branch information
dingyuqi committed Jan 22, 2025
1 parent 422189f commit ae708e1
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/1. 数据库/2024-11-12-Kafka.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,27 @@ Consumer 负责订阅 Kafka 中的 Topic, 并从订阅的 Topic 中拉取消息.
3. 有 Consumer 主动退出 Consumer Group.
4. Consumer Group 订阅的任何 Topic 的分区数量产生变化.

#### 可能造成的影响
1. 重复消费.

Consumer 被移出 Consumer Group 可能还没有提交 offset, Rebalance 时将 Partition 重新分配给其他的 Consumer 可能会造成数据的重复消费.
2. 集群不稳定.

Rebalance 的影响范围是整个 Consumer Group, 影响范围较大.
3. 影响消费速度.

频繁的 Rebalance 反而降低了消费的速度, 因为大部分时间都在重复消费和 Rebalance 本身上了.

#### 避免的措施
1. 业务需求通常无法避免.
2. 合理设置消费者的参数.
1. 避免未能及时发送心跳而 Rebalance.
- session.timeout.ms: 一次 session 连接的超时时间.
- heartbeat.interval.ms: 心跳时间. 一般为超时时间的 1/3. Consumer 在判定为死亡之前能够发送至少 3 轮的心跳请求.
2. 避免因为消费超时而 Rebalance.
- max.poll.interval.ms: 每隔多长时间去拉取消息.
- max.poll.records: 每次拉取的数据条数.

#### 第一阶段 FIND_COORDINATOR
Consumer 需要确定其 Consumer Group 对应的 Group Coordinator 的 Broker 并与其建立连接.

Expand Down

0 comments on commit ae708e1

Please sign in to comment.