# Number of active threads for bulk thread\_pool is equal to number of shards to which write is happening and not a single bulk request

**URL:** https://discuss.elastic.co/t/number-of-active-threads-for-bulk-thread-pool-is-equal-to-number-of-shards-to-which-write-is-happening-and-not-a-single-bulk-request/139723
**Category:** Elasticsearch
**Created:** [July 12, 2018, 10:06am UTC](https://discuss.elastic.co/t/number-of-active-threads-for-bulk-thread-pool-is-equal-to-number-of-shards-to-which-write-is-happening-and-not-a-single-bulk-request/139723 "2018-07-12T10:06:22Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)
#### Post date: [July 12, 2018, 10:06am UTC](https://discuss.elastic.co/t/number-of-active-threads-for-bulk-thread-pool-is-equal-to-number-of-shards-to-which-write-is-happening-and-not-a-single-bulk-request/139723/1 "2018-07-12T10:06:22Z")

</div>

Number of active threads for bulk thread\_pool is equal to number of shards to which write is happening and not a single bulk request.

My understanding was that , active threads in thread\_pool = number of concurrent bulk requests.  
But seems this is equals to the number of shards to which write happens.  
We have a bulk where we are writing to multiple indices in a single bulk request and it seems to exceed active threads + queue size and finally hitting rejection , even though we have only 1 bulk request in parallel.

Is my observation wrong or is Elasticsearch working like this ?

---

<div class="post-metadata">

### Author: ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)
#### Post date: [July 12, 2018, 10:19am UTC](https://discuss.elastic.co/t/number-of-active-threads-for-bulk-thread-pool-is-equal-to-number-of-shards-to-which-write-is-happening-and-not-a-single-bulk-request/139723/2 "2018-07-12T10:19:00Z")

</div>

Seems that is how Elasticsearch works and it is well documented - [https://www.elastic.co/blog/why-am-i-seeing-bulk-rejections-in-my-elasticsearch-cluster](https://www.elastic.co/blog/why-am-i-seeing-bulk-rejections-in-my-elasticsearch-cluster)

But what should be done in instance where I have a bulk which writes to multiple indices ? Number of shards can be of very huge number.

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [July 12, 2018, 10:20am UTC](https://discuss.elastic.co/t/number-of-active-threads-for-bulk-thread-pool-is-equal-to-number-of-shards-to-which-write-is-happening-and-not-a-single-bulk-request/139723/3 "2018-07-12T10:20:59Z")

</div>

What is the use case? How many indices and shards do you have? What is your sharding strategy as you end up writing to so many shards in a single bulk request?

If you have a very large number of shards in your cluster, you may also benefit from [this blog post](https://www.elastic.co/blog/how-many-shards-should-i-have-in-my-elasticsearch-cluster).

---

<div class="post-metadata">

### Author: ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)
#### Post date: [July 12, 2018, 10:37am UTC](https://discuss.elastic.co/t/number-of-active-threads-for-bulk-thread-pool-is-equal-to-number-of-shards-to-which-write-is-happening-and-not-a-single-bulk-request/139723/4 "2018-07-12T10:37:11Z")

</div>

Well , lets assume I have like 50 indices with 5 shards each. Inside my bulk request , each request can go to a different index , which means that number of active threads = concurrency Multiplied by ( number of shards to which write happens ) which could be 1 \* 250 ( worst case , I am writing to all shards ).  
Some of the index requests will fail for sure.

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [July 12, 2018, 10:39am UTC](https://discuss.elastic.co/t/number-of-active-threads-for-bulk-thread-pool-is-equal-to-number-of-shards-to-which-write-is-happening-and-not-a-single-bulk-request/139723/5 "2018-07-12T10:39:54Z")

</div>

If all shards are on a single node that could end up exceeding the queue size. If you can reduce the number of shards per index this would improve. Do you need 5 shards per index?

---

<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: [August 9, 2018, 10:40am UTC](https://discuss.elastic.co/t/number-of-active-threads-for-bulk-thread-pool-is-equal-to-number-of-shards-to-which-write-is-happening-and-not-a-single-bulk-request/139723/6 "2018-08-09T10:40:01Z")

</div>

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