# A question about search threadpool size

**URL:** <https://discuss.elastic.co/t/a-question-about-search-threadpool-size/197745>\
**Category:** Elasticsearch\
**Created:** [September 3, 2019, 1:12am UTC](https://discuss.elastic.co/t/a-question-about-search-threadpool-size/197745 "2019-09-03T01:12:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpgmakervx](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rpgmakervx/32/87245_2.png) [@rpgmakervx](https://discuss.elastic.co/u/rpgmakervx)\
**Post date:** [September 3, 2019, 1:12am UTC](https://discuss.elastic.co/t/a-question-about-search-threadpool-size/197745/1 "2019-09-03T01:12:35Z")

</div>

As org.elasticsearch.threadpool. ExecutorBuilder#applyHardSizeLimit method shown that write threadpool holds a **controllable** core thread count, default could not over 32.

but search will return an unlimit max size which means that when queue is full, thread will be created ulimitly. So why search threadpopl designed like this?

here's the source code:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/6/565906862a5b7cc152b436669187ee8cf12f5274.png)

---

<div class="post-metadata">

**Author:** ![jmorph99](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmorph99/32/53466_2.png) [@jmorph99](https://discuss.elastic.co/u/jmorph99)\
**Post date:** [September 3, 2019, 3:57am UTC](https://discuss.elastic.co/t/a-question-about-search-threadpool-size/197745/2 "2019-09-03T03:57:46Z")

</div>

Neither search or indexing uses a scaling thread pool.

[https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-threadpool.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-threadpool.html)

---

<div class="post-metadata">

**Author:** ![rpgmakervx](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rpgmakervx/32/87245_2.png) [@rpgmakervx](https://discuss.elastic.co/u/rpgmakervx)\
**Post date:** [September 3, 2019, 4:11am UTC](https://discuss.elastic.co/t/a-question-about-search-threadpool-size/197745/3 "2019-09-03T04:11:33Z")

</div>

search uses fixed threadpool, whitch means it can reach a huge number of threads。

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/e/9e52d148ec4c3e772dac1abccd11067963d29cc4.png)  
core size equals to the above applyHardSizeLimit method's result。

---

<div class="post-metadata">

**Author:** ![jmorph99](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmorph99/32/53466_2.png) [@jmorph99](https://discuss.elastic.co/u/jmorph99)\
**Post date:** [September 3, 2019, 1:42pm UTC](https://discuss.elastic.co/t/a-question-about-search-threadpool-size/197745/4 "2019-09-03T13:42:58Z")

</div>

A fixed thread pool means that it limits the number of threads. It will queue up tasks until a thread becomes available. If the queue becomes full it will reject further requests with a 429 error. A scaling thread pool can create unlimited threads.

---

<div class="post-metadata">

**Author:** ![rpgmakervx](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rpgmakervx/32/87245_2.png) [@rpgmakervx](https://discuss.elastic.co/u/rpgmakervx)\
**Post date:** [September 4, 2019, 1:22am UTC](https://discuss.elastic.co/t/a-question-about-search-threadpool-size/197745/5 "2019-09-04T01:22:45Z")

</div>

In version 5.4.1. if someone config thread\_pool.search.size=1000(or bigger) by accident , there will be no limit on the maximum number of search threads (applyHardSizeLimit method shown that the max thread could reach Integer.MAX\_VALUE)，but if someone set thread\_pool.index.size=1024 by accident, the index thread will not exceeding 32。 I mean maybe search thread should also do the same as index thread to protect this human error ?

---

<div class="post-metadata">

**Author:** ![jmorph99](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmorph99/32/53466_2.png) [@jmorph99](https://discuss.elastic.co/u/jmorph99)\
**Post date:** [September 4, 2019, 2:57pm UTC](https://discuss.elastic.co/t/a-question-about-search-threadpool-size/197745/6 "2019-09-04T14:57:06Z")

</div>

Sounds like a 5.4.1 bug.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [September 4, 2019, 3:25pm UTC](https://discuss.elastic.co/t/a-question-about-search-threadpool-size/197745/7 "2019-09-04T15:25:01Z")

</div>

See [Remove artificial default processors limit by jasontedor · Pull Request #20874 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/pull/20874), in particular:

> There are some caveats still to having too many concurrent indexing  
> threads as it can lead to too many little segments...

AIUI this is why the number of indexing threads is more strictly bounded than most of the other thread pools: it leads to non-obvious performance issues that might persist even after the pool size is reduced. On the other hand if you want 1000 search threads and your node can't handle it then it will fail in much more obvious ways.

---

<div class="post-metadata">

**Author:** ![rpgmakervx](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rpgmakervx/32/87245_2.png) [@rpgmakervx](https://discuss.elastic.co/u/rpgmakervx)\
**Post date:** [September 5, 2019, 2:24am UTC](https://discuss.elastic.co/t/a-question-about-search-threadpool-size/197745/9 "2019-09-05T02:24:33Z")

</div>

I found that in recent version, this method in ExecutorBuilder is also unlimit to the search threadool's size.

---

<div class="post-metadata">

**Author:** ![rpgmakervx](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rpgmakervx/32/87245_2.png) [@rpgmakervx](https://discuss.elastic.co/u/rpgmakervx)\
**Post date:** [September 5, 2019, 2:27am UTC](https://discuss.elastic.co/t/a-question-about-search-threadpool-size/197745/10 "2019-09-05T02:27:20Z")

</div>

so I think all kind's of threapool's core size should be limited to protect from oom or other potential danger

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [September 5, 2019, 6:51am UTC](https://discuss.elastic.co/t/a-question-about-search-threadpool-size/197745/11 "2019-09-05T06:51:12Z")

</div>

I'm wondering why this is of importance to you. If you don't want so many threads, don't ask for so many threads. I can't think of an easy way to choose a limit that protects the cases that need it without unduly limiting the cases that don't. There are other protections against OOMs (in more recent versions anyway) that should help here.

---

<div class="post-metadata">

**Author:** ![rpgmakervx](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rpgmakervx/32/87245_2.png) [@rpgmakervx](https://discuss.elastic.co/u/rpgmakervx)\
**Post date:** [September 16, 2019, 9:52am UTC](https://discuss.elastic.co/t/a-question-about-search-threadpool-size/197745/12 "2019-09-16T09:52:12Z")

</div>

Just as I said, by accident, and some developer might didn't realize this problem。 And on the other hand, I want to know why index/bulk limit thread count but search don't, what will happen if search make this limit.

---

<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:** [October 14, 2019, 9:52am UTC](https://discuss.elastic.co/t/a-question-about-search-threadpool-size/197745/13 "2019-10-14T09:52:14Z")

</div>

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