# Any reason why having 1 shard is slower than 5 shards?

**URL:** <https://discuss.elastic.co/t/any-reason-why-having-1-shard-is-slower-than-5-shards/223429>\
**Category:** Elasticsearch\
**Created:** [March 12, 2020, 11:56pm UTC](https://discuss.elastic.co/t/any-reason-why-having-1-shard-is-slower-than-5-shards/223429 "2020-03-12T23:56:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NewHere](https://avatars.discourse-cdn.com/v4/letter/n/5e9695/32.png) [@NewHere](https://discuss.elastic.co/u/NewHere)\
**Post date:** [March 12, 2020, 11:56pm UTC](https://discuss.elastic.co/t/any-reason-why-having-1-shard-is-slower-than-5-shards/223429/1 "2020-03-12T23:56:12Z")

</div>

According to various online sources (e.g. [https://www.elastic.co/guide/en/elasticsearch/reference/master/tune-for-search-speed.html](https://www.elastic.co/guide/en/elasticsearch/reference/master/tune-for-search-speed.html)), they all said fewer shard the faster.

However, my experience was 5 shards index returned query results 2 times faster than 1 shard. Everything was the same (same computer, same ES version, same data, same test query), only thing different was the number of shards. Any reason for that?

Some stats of my environments:  
Setup 1 - 16GB ram, 1 node, **5 primary shards** , 4GB heap (-Xms4g -Xmx4g)  
Total main record 2.5m, total documents 3.8m (including nested), total index size 1GB  
**test\_index 0 p 771822 209.1mb**  
**test\_index 1 p 770783 206.7mb**  
**test\_index 2 p 773046 205.7mb**  
**test\_index 3 p 770961 209.9mb**  
**test\_index 4 p 771440 205.7mb**  
Test query with 25 nested queries wrapped in dis\_max took **13s**

Setup 2 - 16GB ram, 1 node, **1 primary shard** , 4GB heap (-Xms4g -Xmx4g)  
Total main record 2.5m, total documents 3.8m (including nested), total index size 1GB  
**test\_index 0 p 3858052 1000.8mb**  
A query with 25 nested queries wrapped in dis\_max took **26s**

---

<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:** [March 13, 2020, 2:11am UTC](https://discuss.elastic.co/t/any-reason-why-having-1-shard-is-slower-than-5-shards/223429/2 "2020-03-13T02:11:19Z")

</div>

It sounds like you have a quite complex query run against an index that fully fits within the operating system page cache. No disk I/O should be required here. You also have a low query concurrency as you run just a f SF ingle query. I would expect this to make your scenario largely CPU bound.

As each query basically is executed in a single thread against each shard (different shards are processed in parallel) your query against a single shard can only use one core, which is likely to make it slower in this scenario. Note however that querying 5 shards is not 5 times faster. If your query concurrency was higher or you had more data this could very well change though.

Query latency and optimal shard size and count will depend on a large number of factors, so it is important to always test with a scenario as realistic as possible before you draw any conclusions.

---

<div class="post-metadata">

**Author:** ![NewHere](https://avatars.discourse-cdn.com/v4/letter/n/5e9695/32.png) [@NewHere](https://discuss.elastic.co/u/NewHere)\
**Post date:** [March 13, 2020, 3:31am UTC](https://discuss.elastic.co/t/any-reason-why-having-1-shard-is-slower-than-5-shards/223429/3 "2020-03-13T03:31:28Z")

</div>

Thank you for your response. You were right that CPU was maxed out while processing the test query.

So in my case of complex queries I actually need to increase the shard count rather than to reduce it?

---

<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:** [March 13, 2020, 6:21am UTC](https://discuss.elastic.co/t/any-reason-why-having-1-shard-is-slower-than-5-shards/223429/4 "2020-03-13T06:21:39Z")

</div>

If this is the full data set you will have in production and you expect very low query concurrency that would appear to be the case.

---

<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:** [April 10, 2020, 6:21am UTC](https://discuss.elastic.co/t/any-reason-why-having-1-shard-is-slower-than-5-shards/223429/5 "2020-04-10T06:21:42Z")

</div>

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