简体   繁体   English

Kafka Streams 本地存储分区分配不平衡

[英]Kafka Streams localstore partitions assignment unbalanced

First off all, sorry if my terminology is not precise I am very new to kafka and i have read as most as i could.首先,对不起,如果我的术语不准确,我对 kafka 很陌生,我已经尽可能多地阅读了。 We have a service which uses kafkastreams, kafka version: 2.3.1.我们有一个使用 kafkastreams 的服务,kafka 版本:2.3.1。 The stream app has a stream topology which reads from a "topicA", performs a convertion and publishes into another topic "topicB" which then is consumed by another stream of the topology and aggregates it using a Ktable ( localstore ).流应用程序有一个流拓扑,它从“topicA”读取,执行转换并发布到另一个主题“topicB”,然后由另一个拓扑流使用并使用 Ktable ( localstore ) 聚合它。 A listener publishes the ktable changes into another topic.侦听器将 ktable 更改发布到另一个主题中。

The topics has 24 partitions.主题有 24 个分区。 We have 2 instances of this service in different machines with 4 stream threads each.我们在不同的机器上有 2 个这个服务的实例,每个实例有 4 个流线程。 The problem is, the partitions that use local store are assigned all to the same instance.问题是,使用本地存储的分区都分配给同一个实例。 Hence the disk usage, rebalance, performance is awful.因此磁盘使用、重新平衡、性能都很糟糕。

Also something unexpected to me, if I check the group assignments on the Kafka broker i see: (Removed other partitions for readability )还有一些出乎我的意料,如果我检查 Kafka 代理上的组分配,我会看到:(删除了其他分区以提高可读性)

 GROUP CONSUMER-ID HOST CLIENT-ID #PARTITIONS ASSIGNMENT fj.TheAggregation.TST.V1.PERF fj.TheAggregation.TST.V1.PERF-6898e899-7722-421a-8841-f8e45b074981-StreamThread-3-consumer-c089baaa-343b-484f-add6-aca12572e2a5 10.11.200.115/10.11.200.115 fj.TheAggregation.TST.V1.PERF-6898e899-7722-421a-8841-f8e45b074981-StreamThread-3-consumer 54 fj.TheAggregationDocument.TST.V1.PERF(4,8,12,16,20) fj.TheAggregation.TST.V1.PERF fj.TheAggregation.TST.V1.PERF-6898e899-7722-421a-8841-f8e45b074981-StreamThread-2-consumer-f5e2d4e3-feee-4778-8ab8-ec4dd770541a 10.11.200.115/10.11.200.115 fj.TheAggregation.TST.V1.PERF-6898e899-7722-421a-8841-f8e45b074981-StreamThread-2-consumer 54 fj.TheAggregationDocument.TST.V1.PERF(5,9,13,17,21) fj.TheAggregation.TST.V1.PERF fj.TheAggregation.TST.V1.PERF-0733344b-bd8d-40d6-ad07-4fc93de76cf2-StreamThread-4-consumer-63371f35-118a-44e0-bc9b-d403fb59384d 10.11.200.114/10.11.200.114 fj.TheAggregation.TST.V1.PERF-0733344b-bd8d-40d6-ad07-4fc93de76cf2-StreamThread-4-consumer 54 fj.TheAggregationDocument.TST.V1.PERF(2) fj.TheAggregation.TST.V1.PERF fj.TheAggregation.TST.V1.PERF-0733344b-bd8d-40d6-ad07-4fc93de76cf2-StreamThread-1-consumer-714f0fee-b001-4b16-8b5b-6ab8935becfd 10.11.200.114/10.11.200.114 fj.TheAggregation.TST.V1.PERF-0733344b-bd8d-40d6-ad07-4fc93de76cf2-StreamThread-1-consumer 54 fj.TheAggregationDocument.TST.V1.PERF(0) fj.TheAggregation.TST.V1.PERF fj.TheAggregation.TST.V1.PERF-0733344b-bd8d-40d6-ad07-4fc93de76cf2-StreamThread-2-consumer-d14e2e20-9aad-4a20-a295-83621a76b099 10.11.200.114/10.11.200.114 fj.TheAggregation.TST.V1.PERF-0733344b-bd8d-40d6-ad07-4fc93de76cf2-StreamThread-2-consumer 54 fj.TheAggregationDocument.TST.V1.PERF(1) fj.TheAggregation.TST.V1.PERF fj.TheAggregation.TST.V1.PERF-6898e899-7722-421a-8841-f8e45b074981-StreamThread-4-consumer-14f390d9-f4f4-4e70-8e8d-62a79427c4e6 10.11.200.115/10.11.200.115 fj.TheAggregation.TST.V1.PERF-6898e899-7722-421a-8841-f8e45b074981-StreamThread-4-consumer 54 fj.TheAggregationDocument.TST.V1.PERF(7,11,15,19,23) fj.TheAggregation.TST.V1.PERF fj.TheAggregation.TST.V1.PERF-6898e899-7722-421a-8841-f8e45b074981-StreamThread-1-consumer-57d2f85b-50f8-4649-8080-bbaaa6ea500f 10.11.200.115/10.11.200.115 fj.TheAggregation.TST.V1.PERF-6898e899-7722-421a-8841-f8e45b074981-StreamThread-1-consumer 54 fj.TheAggregationDocument.TST.V1.PERF(6,10,14,18,22) fj.TheAggregation.TST.V1.PERF fj.TheAggregation.TST.V1.PERF-0733344b-bd8d-40d6-ad07-4fc93de76cf2-StreamThread-3-consumer-184f3a99-1159-44d7-84c6-e7aa70c484c0 10.11.200.114/10.11.200.114 fj.TheAggregation.TST.V1.PERF-0733344b-bd8d-40d6-ad07-4fc93de76cf2-StreamThread-3-consumer 54 fj.TheAggregationDocument.TST.V1.PERF(3)

so each stream service has 54 partitions assigned in total, however they are not evenly assigned.所以每个流服务总共分配了 54 个分区,但是它们不是均匀分配的。 Also if i check the local store on each instance i see that the stream ktable are all in the same node, even though the broker states that some of the partition's are assigned to another instance.此外,如果我检查每个实例上的本地存储,我会看到流 ktable 都在同一个节点中,即使代理声明某些分区已分配给另一个实例。 So the data provided by the broker does not seem to match the streamapp state.所以broker提供的数据似乎与streamapp状态不匹配。

Is there a way to ensure that GroupLeader assigns partitions evenly?有没有办法确保 GroupLeader 平均分配分区? I would expect to have some way to specify that or assign some kind of "weight" to each stream so the GroupLeader is able to distribute resources intensive streams evenly among the service instances or at least not so unbalanced.我希望有某种方法来指定或为每个流分配某种“权重”,以便 GroupLeader 能够在服务实例之间均匀分配资源密集型流,或者至少不会那么不平衡。 Btw, is there some kafka users group recommended to ask this kind of things?顺便说一句,有没有推荐的 kafka 用户组询问这种事情? Thanks谢谢

There was a lot of improvements to the streams assignor in 2.6 ( https://cwiki.apache.org/confluence/display/KAFKA/KIP-441%3A+Smooth+Scaling+Out+for+Kafka+Streams ) you can read about them here.您可以阅读 2.6 ( https://cwiki.apache.org/confluence/display/KAFKA/KIP-441%3A+Smooth+Scaling+Out+for+Kafka+Streams ) 中的流分配器有很多改进关于他们在这里。

I don't know if they will fix your problem but it should help.我不知道他们是否会解决您的问题,但应该会有所帮助。 It does treat stateful task like ktables differently and should load them better.它确实以不同的方式对待像 ktables 这样的有状态任务,并且应该更好地加载它们。

If you cannot upgrade from 2.3.1 you might try different names.如果您无法从 2.3.1 升级,您可以尝试不同的名称。 You might just be getting unlucky hashes.你可能只是得到了不幸的哈希值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM