# Consumer threads for topics\_pattern

**URL:** <https://discuss.elastic.co/t/consumer-threads-for-topics-pattern/245303>\
**Category:** Logstash\
**Created:** [August 17, 2020, 6:17pm UTC](https://discuss.elastic.co/t/consumer-threads-for-topics-pattern/245303 "2020-08-17T18:17:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarunwadhwa13](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tarunwadhwa13/32/46404_2.png) [@tarunwadhwa13](https://discuss.elastic.co/u/tarunwadhwa13)\
**Post date:** [August 17, 2020, 6:17pm UTC](https://discuss.elastic.co/t/consumer-threads-for-topics-pattern/245303/1 "2020-08-17T18:17:41Z")

</div>

The doc mentioned that consumer thread should be equal to number of partition or divided by number of logstash instances if more than 1 is running.

Just wanted to understand how do i calculate the value of consumer threads when topics\_pattern is used? Say 1 topic has 4 partitions and I am expecting 100 topic in topics\_pattern then should i keep consumer threads as 400?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 17, 2020, 6:48pm UTC](https://discuss.elastic.co/t/consumer-threads-for-topics-pattern/245303/2 "2020-08-17T18:48:28Z")

</div>

Matching the number of threads and partitions matters for small numbers of partitions. If you have 3 partitions and 4 threads then one will be idle. If you have 3 partitions and 2 threads then one will service 2 partitions and do twice as much work as the other.

I cannot see much point in having the number of threads much larger than the number of CPUs that will run them.

---

<div class="post-metadata">

**Author:** ![tarunwadhwa13](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tarunwadhwa13/32/46404_2.png) [@tarunwadhwa13](https://discuss.elastic.co/u/tarunwadhwa13)\
**Post date:** [August 17, 2020, 7:01pm UTC](https://discuss.elastic.co/t/consumer-threads-for-topics-pattern/245303/3 "2020-08-17T19:01:30Z")

</div>

> [@tarunwadhwa13](#):
>
> Just wanted to understand how do i calculate the value of consumer threads when topics\_pattern is used? Say 1 topic has 4 partitions and I am expecting 100 topic in topics\_pattern then should i keep consumer threads as 400?

Thanks for the reply !!  
I understand the idea of consumer threads and workers.. The question was if a topics\_pattern covers 100 topics and i use consumer\_threads =\> 1 then will logstash auto spawn 1 consumer thread per topic ? or i need to mention consumer\_threads =\> 100 for 100 topics  
(Assuming all topics with single partition)

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 17, 2020, 7:43pm UTC](https://discuss.elastic.co/t/consumer-threads-for-topics-pattern/245303/4 "2020-08-17T19:43:52Z")

</div>

The number of consumer threads will be equal to consumer\_threads. They get [spun up](https://github.com/logstash-plugins/logstash-input-kafka/blob/66e6a26ce97b29beb03b4196316eb84852887d52/lib/logstash/inputs/kafka.rb#L226) when the input is started, and only [later](https://github.com/logstash-plugins/logstash-input-kafka/blob/66e6a26ce97b29beb03b4196316eb84852887d52/lib/logstash/inputs/kafka.rb#L249) do they subscribe to the topics\_pattern.

Of course I could be misunderstanding the code, but that is how I interpret it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 14, 2020, 7:44pm UTC](https://discuss.elastic.co/t/consumer-threads-for-topics-pattern/245303/5 "2020-09-14T19:44:06Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
