Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache kafka 卡夫卡:主题中奇怪的分区分配_Apache Kafka_Kafka Consumer Api_Spring Kafka - Fatal编程技术网

Apache kafka 卡夫卡:主题中奇怪的分区分配

Apache kafka 卡夫卡:主题中奇怪的分区分配,apache-kafka,kafka-consumer-api,spring-kafka,Apache Kafka,Kafka Consumer Api,Spring Kafka,我不知道如何解释我面对卡夫卡的问题,但我会尽我最大的努力。我在同一消费者组中有一组4个消费者,名为: 绝对地,绝对地,绝对地 从具有5个分区的主题消费;因此,组中的每个使用者被分配到1个分区,1个使用者被分配到2个分区,以便在4个使用者之间公平地分配5个分区 但由于某些原因,我无法理解,最初的分配变成了只有2个消费者被分配到所有可用分区,即1个消费者有3个分区,1个消费者有2个分区。但是,理论上同一消费群体中仍有4名消费者: [medinen@ocvlp-rks001 kafka_2.11-0.

我不知道如何解释我面对卡夫卡的问题,但我会尽我最大的努力。我在同一消费者组中有一组4个消费者,名为:

绝对地,绝对地,绝对地

从具有5个分区的主题消费;因此,组中的每个使用者被分配到1个分区,1个使用者被分配到2个分区,以便在4个使用者之间公平地分配5个分区

但由于某些原因,我无法理解,最初的分配变成了只有2个消费者被分配到所有可用分区,即1个消费者有3个分区,1个消费者有2个分区。但是,理论上同一消费群体中仍有4名消费者:

[medinen@ocvlp-rks001 kafka_2.11-0.10.0.1]$ ./bin/kafka-run-class.sh kafka.admin.ConsumerGroupCommand --new-consumer --bootstrap-server localhost:9092 --describe --group absolutegrounds.helper.processor
GROUP                          TOPIC                          PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG             OWNER
absolutegrounds.helper.processor AG_TASK_SOURCE                 0          27286           31535           4249            consumer-1_/10.132.9.128
absolutegrounds.helper.processor AG_TASK_SOURCE                 1          28015           28045           30              consumer-1_/10.132.9.128
absolutegrounds.helper.processor AG_TASK_SOURCE                 2          35437           40091           4654            consumer-1_/10.132.9.128
absolutegrounds.helper.processor AG_TASK_SOURCE                 3          31765           31874           109             consumer-1_/10.132.8.23
absolutegrounds.helper.processor AG_TASK_SOURCE                 4          33279           38003           4724            consumer-1_/10.132.8.23
最奇怪的行为是,根据我在应用程序中看到的日志,被排除在消费者组之外的其他两个消费者(根据上面卡夫卡的回复)似乎仍在使用该主题,尽管我在任何地方都找不到他们作为消费者组的一部分。更奇怪的是,一个使用者应该被分配给主题中的所有分区,而另一个使用者只被分配给分区4。请参阅应用程序日志(这是一个使用Spring Kafka的Spring引导应用程序):

第一左消费者:

-  - 08/05/2017 12:27:29.119 - [-kafka-consumer-1] INFO  o.a.k.c.c.i.ConsumerCoordinator - Setting newly assigned partitions [AG_TASK_SOURCE-0, AG_TASK_SOURCE-1, AG_TASK_SOURCE-2, AG_TASK_SOURCE-3, AG_TASK_SOURCE-4] for group absolutegrounds.helper.processor
 -  - 08/05/2017 12:27:19.044 - [-kafka-consumer-1] INFO  o.a.k.c.c.i.ConsumerCoordinator - Setting newly assigned partitions [AG_TASK_SOURCE-4] for group absolutegrounds.helper.processor
左二消费者:

-  - 08/05/2017 12:27:29.119 - [-kafka-consumer-1] INFO  o.a.k.c.c.i.ConsumerCoordinator - Setting newly assigned partitions [AG_TASK_SOURCE-0, AG_TASK_SOURCE-1, AG_TASK_SOURCE-2, AG_TASK_SOURCE-3, AG_TASK_SOURCE-4] for group absolutegrounds.helper.processor
 -  - 08/05/2017 12:27:19.044 - [-kafka-consumer-1] INFO  o.a.k.c.c.i.ConsumerCoordinator - Setting newly assigned partitions [AG_TASK_SOURCE-4] for group absolutegrounds.helper.processor
为了理解这种行为背后的原因,我研究了存储消费者所有补偿的主题:

__消费者补偿

使用此命令:

kafka/kafka_2.11-0.10.0.1/bin/kafka-console-consumer.sh --consumer.config /tmp/consumer.config --formatter "kafka.coordinator.GroupMetadataManager\$GroupMetadataMessageFormatter" --zookeeper ocvlp-rks003:2181 --topic __consumer_offsets --from-beginning | grep "absolutegrounds.helper.processor"
这就是我发现的:

absolutegrounds.helper.processor::[absolutegrounds.helper.processor,consumer,Stable,Map(consumer-1-170fb8f6-c8d3-4782-8940-350673b859cb -> [consumer-1-170fb8f6-c8d3-4782-8940-350673b859cb,consumer-1,/10.132.8.23,10000], consumer-1-b8d3afc0-159e-4660-bc65-faf68900c332 -> [consumer-1-b8d3afc0-159e-4660-bc65-faf68900c332,consumer-1,/10.132.9.128,10000], consumer-1-dddf10ad-187b-4a29-9996-e05edaad3caf -> [consumer-1-dddf10ad-187b-4a29-9996-e05edaad3caf,consumer-1,/10.132.8.22,10000], consumer-1-2e4069f6-f3a8-4ede-a4f4-aadce6a3adb7 -> [consumer-1-2e4069f6-f3a8-4ede-a4f4-aadce6a3adb7,consumer-1,/10.132.9.129,10000])]

absolutegrounds.helper.processor::[absolutegrounds.helper.processor,consumer,Stable,Map(consumer-1-66de4a46-538c-425f-8e95-5a00ff5eb5fd -> [consumer-1-66de4a46-538c-425f-8e95-5a00ff5eb5fd,consumer-1,/10.132.9.129,10000])]

absolutegrounds.helper.processor::[absolutegrounds.helper.processor,consumer,Stable,Map(consumer-1-5b96166e-e528-48f7-8f6e-18a67328eae6 -> [consumer-1-5b96166e-e528-48f7-8f6e-18a67328eae6,consumer-1,/10.132.9.128,10000], consumer-1-dcfff37a-8ad3-403c-a070-cca82a1f6d21 -> [consumer-1-dcfff37a-8ad3-403c-a070-cca82a1f6d21,consumer-1,/10.132.8.23,10000])]

absolutegrounds.helper.processor::[absolutegrounds.helper.processor,consumer,Stable,Map(consumer-1-5b96166e-e528-48f7-8f6e-18a67328eae6 -> [consumer-1-5b96166e-e528-48f7-8f6e-18a67328eae6,consumer-1,/10.132.9.128,10000], consumer-1-dcfff37a-8ad3-403c-a070-cca82a1f6d21 -> [consumer-1-dcfff37a-8ad3-403c-a070-cca82a1f6d21,consumer-1,/10.132.8.23,10000])]
从Kafka的响应中,我可以看到,在某个时间点,所有4个消费者都正确地分布在分区之间:

absolutegrounds.helper.processor::[absolutegrounds.helper.processor,consumer,Stable,Map(consumer-1-170fb8f6-c8d3-4782-8940-350673b859cb -> [consumer-1-170fb8f6-c8d3-4782-8940-350673b859cb,consumer-1,/10.132.8.23,10000], consumer-1-b8d3afc0-159e-4660-bc65-faf68900c332 -> [consumer-1-b8d3afc0-159e-4660-bc65-faf68900c332,consumer-1,/10.132.9.128,10000], consumer-1-dddf10ad-187b-4a29-9996-e05edaad3caf -> [consumer-1-dddf10ad-187b-4a29-9996-e05edaad3caf,consumer-1,/10.132.8.22,10000], consumer-1-2e4069f6-f3a8-4ede-a4f4-aadce6a3adb7 -> [consumer-1-2e4069f6-f3a8-4ede-a4f4-aadce6a3adb7,consumer-1,/10.132.9.129,10000])]
但是,在稍后的某个时刻,分配更改为当前场景,在该场景中,消费者组中的4个消费者中只有2个被分配了分区

我一直在努力理解是什么导致了这种情况,但我找不到一个有效的答案来解决它


有人能帮忙吗?谢谢。

我认为问题在于听众反应迟钝和不断的重新平衡。最好升级到卡夫卡
0.10.2
,自
0.10.1
以来,在卡夫卡的炉膛跳动得到了改善。因此,任何迟钝的听众都不会对消费者群体产生影响,也不会经常导致重新平衡。但你认为我的问题实际上与迟钝的听众有关吗?这4个使用者是同一个Spring Boot应用程序,它们的处理应该是相似的。我不知道是什么导致了重新平衡,但您的观察结果推动了这个过程……您的使用者是否定期调用poll(),并且比为max.poll.interval.ms配置的时间还要快?如果不是的话,他们将被逐出消费者群体是的,汉斯,我想这是由Spring Kafka自动处理的。我认为问题在于缓慢的听众和不断的重新平衡。最好升级到卡夫卡
0.10.2
,自
0.10.1
以来,在卡夫卡的炉膛跳动得到了改善。因此,任何迟钝的听众都不会对消费者群体产生影响,也不会经常导致重新平衡。但你认为我的问题实际上与迟钝的听众有关吗?这4个使用者是同一个Spring Boot应用程序,它们的处理应该是相似的。我不知道是什么导致了重新平衡,但您的观察结果推动了这个过程……您的使用者是否定期调用poll(),并且比为max.poll.interval.ms配置的时间还要快?如果不是的话,他们将被逐出消费群体是的,汉斯,我想这是弹簧卡夫卡自动处理的。