问题

项目使用spring-kafka操作消费kafka
近期出现消费速度变慢,consumer消费一条数据平均需要200ms的时间,并且频繁发生,consumer会停止消费十几秒。

日志分析

以下为日志记录,consumer会时长从消费组中掉出再重新加入

o.a.k.c.c.i.AbstractCoordinator:542 - Marking the coordinator 127.0.0.1:9092 (id: 2147483643 rack: null) dead for group group.id 
o.a.k.c.c.i.AbstractCoordinator:505 - Discovered coordinator 127.0.0.1:9092 (id: 2147483643 rack: null) for group group.id. 
o.a.k.c.c.i.ConsumerCoordinator:292 - Revoking previously assigned partitions [topic-12] for group group.id 
o.a.k.c.c.i.AbstractCoordinator:326 - (Re-)joining group group.id 
o.a.k.c.c.i.AbstractCoordinator$SyncGroupResponseHandler:434 - Successfully joined group group.id with generation 12182 
o.a.k.c.c.i.ConsumerCoordinator:231 - Setting newly assigned partitions [topic-12] for group group.id 

解决方案

kafka服务配置文件server.properties提高系统配置参数

#Broker处理消息的最大线程数
num.network.threads=cpu核数加1
#Broker处理磁盘IO的线程数
num.io.threads=cpu核数2倍,最大不超过3倍

备份并重启kafka服务