问题
I have a spring boot kafka stream application with 2 topics consider topics A and B.Topic A has 16 partition and Topic B has 1 partition.Consider the application is deployed in 1 instance having num.stream.threads
=16.
I ran kafka-consumer-groups.bat command to check how the threads are assigned to the partition in group,got the following output.Topic A and B assigned with 16 threads where 14 threads in topic B is idle.
kafka-consumer-groups.bat --bootstrap-server 0.0.0.0:9092 --group <topic-AGroupName> -describe
TOPIC PARTITION CLIENT-ID
topic-A 0 topic-AGroupStreamThread-429-consumer
topic-A 10 topic-AGroupStreamThread-422-consumer
topic-A 6 topic-AGroupStreamThread-425-consumer
topic-A 14 topic-AGroupStreamThread-431-consumer
topic-A 7 topic-AGroupStreamThread-420-consumer
topic-A 8 topic-AGroupStreamThread-428-consumer
topic-A 11 topic-AGroupStreamThread-430-consumer
topic-A 4 topic-AGroupStreamThread-417-consumer
topic-A 2 topic-AGroupStreamThread-427-consumer
topic-A 1 topic-AGroupStreamThread-418-consumer
topic-A 15 topic-AGroupStreamThread-421-consumer
topic-A 3 topic-AGroupStreamThread-424-consumer
topic-A 9 topic-AGroupStreamThread-419-consumer
topic-A 12 topic-AGroupStreamThread-426-consumer
topic-A 13 topic-AGroupStreamThread-432-consumer
topic-A 5 topic-AGroupStreamThread-423-consumer
kafka-consumer-groups.bat --bootstrap-server 0.0.0.0:9092 --group <topic-BGroupName> -describe
TOPIC PARTITION CLIENT-ID
topic-BGroup-result-repartition 0 topic-BGroupStreamThread-683-consumer
topic-B 0 topic-BGroupStreamThread-678-consumer
- - topic-BGroupStreamThread-685-consumer
- - topic-BGroupStreamThread-675-consumer
- - topic-BGroupStreamThread-673-consumer
- - topic-BGroupStreamThread-680-consumer
- - topic-BGroupStreamThread-688-consumer
- - topic-BGroupStreamThread-674-consumer
- - topic-BGroupStreamThread-679-consumer
- - topic-BGroupStreamThread-677-consumer
- - topic-BGroupStreamThread-687-consumer
- - topic-BGroupStreamThread-686-consumer
- - topic-BGroupStreamThread-676-consumer
- - topic-BGroupStreamThread-684-consumer
- - topic-BGroupStreamThread-682-consumer
- - topic-BGroupStreamThread-681-consumer
How to avoid the idle threads in topic-B or is there any options available to set num.stream.threads per topic?
回答1:
You can set the concurrency property on the actual input binding. For e.g. spring.cloud.stream.kafka.streams.bindings.<input-binding-name>.consumer.concurrency
. This gets mapped to num.stream.threads
behind the scenes per input binding. See if that works and please let us know if you see any issues.
来源:https://stackoverflow.com/questions/60431844/num-stream-threads-creating-idle-threads