Reputation: 1442
I subscribe to Kafka Topics by RegExp. There are 5 topics matching the given pattern. Four of them has 10 partitions. And the last topic has 12 partitions. So, there are 52 partitions at all.
I have 5 running instances and each of them starts 10 consumers. So, there are 50 consumers at all. I expect that the load is spread horizontally across all the consumers. So, each consumer reads 1 partition except two of them because total number of consumers is less than the whole partitions count.
Though the reality is a bit different.
In short, here is what happens
Is there any way to force Kafka consumer to read 1 partition maximum with RegExp subscription? In this case, I can make all consumers start work. Or maybe there is a different approach that allows to read multiple topics respecting the number of partitions and running consumers?
Upvotes: 1
Views: 668
Reputation: 1442
Well, it's about partition.assignment.strategy Kafka property. The default value is RangeAssignor
which leads to assigning partitions on topic basis. That leads to spreading load between consumers unfairly.
We set the property to RoundRobinAssignor
and it helped.
Though you should be careful when you deploy new version with different partition.assignment.strategy
. Suppose you have 5 running consumers with RangeAssignor
strategy. Then you redeploy one with RoundRobinAssignor
strategy. In this case, you get an exception on consumer replacement. Because all consumers in one consumer group should provide the same partition.assignment.strategy
. The problem is described in this StackOverflow question
So, if you want to change the partition.assignment.strategy
, you have several options:
group.id
for the new consumers.Both of these ways have pros and cons.
Upvotes: 0