操作 Kafka 需要监视关键指标——特别是消费者延迟(消费者落后多少)——加上 broker 健康状态、吞吐量和分区状态。理解监视和消费者延迟对于可靠地运行 Kafka 很重要。
消费者延迟(一个关键指标)
CONSUMER LAG → how far BEHIND a consumer is = (latest offset) − (consumer's committed offset):
→ high/growing lag → the consumer can't keep up with the production rate (a problem!)
→ indicates: slow processing, too few consumers, a stuck/failed consumer, or a traffic spike
→ monitor lag → detect when consumers fall behind (a primary Kafka health signal)
处理消费者延迟
✓ ADD CONSUMERS (scale the group, up to partition count) → more parallel processing
✓ ADD PARTITIONS → enable more consumer parallelism (if at the consumer limit)
✓ OPTIMIZE consumer processing → make it faster (batch, async, efficient code)
✓ Investigate stuck/failing consumers; check for rebalancing issues
✓ Scale based on lag (auto-scaling consumers on lag is common)
