# Elasticsearch same query has different performance

**URL:** <https://discuss.elastic.co/t/elasticsearch-same-query-has-different-performance/132765>\
**Category:** Elasticsearch\
**Created:** [May 22, 2018, 9:20am UTC](https://discuss.elastic.co/t/elasticsearch-same-query-has-different-performance/132765 "2018-05-22T09:20:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ans76](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ans76/32/31446_2.png) [@ans76](https://discuss.elastic.co/u/ans76)\
**Post date:** [May 22, 2018, 9:20am UTC](https://discuss.elastic.co/t/elasticsearch-same-query-has-different-performance/132765/1 "2018-05-22T09:20:33Z")

</div>

I have 2 nodes in my cluster.  
n1: [master:true data:true] 8GB RAM 500GB Disk space  
n2: [master:false data:true] 8GB RAM 500GB Disk space

Only one index for test(about 20000 docs), 5shards, 1replica  
Run the same query 10000+ times in one thread, cost of time like:

1. 5ms
2. 13ms
3. 4ms
4. 12ms
5. 4ms
6. 13ms  
....

Odd tests perform much better than even tests, any idea about this?

---

<div class="post-metadata">

**Author:** ![eedugon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eedugon/32/45404_2.png) [@eedugon](https://discuss.elastic.co/u/eedugon)\
**Post date:** [May 22, 2018, 8:06pm UTC](https://discuss.elastic.co/t/elasticsearch-same-query-has-different-performance/132765/2 "2018-05-22T20:06:25Z")

</div>

Hi @ans76,

From where are you running the tests and towards what node? Each time towards one of the nodes? Have you tried running 100 times the same query towards the same node and then switching to another node?

Also take a look to the query and the data you are retrieving. Check the size of the documents and data, as maybe the JVM is doing garbage collections and you need to adapt the HEAP size every 2 requests, not sure.

You can check the amount of GCs via \_node/stats API (`_node/stats/jvm?pretty` I guess).

Hope this is helpfull...

Regards and good luck!  
Eduardo

---

<div class="post-metadata">

**Author:** ![ans76](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ans76/32/31446_2.png) [@ans76](https://discuss.elastic.co/u/ans76)\
**Post date:** [May 23, 2018, 2:20am UTC](https://discuss.elastic.co/t/elasticsearch-same-query-has-different-performance/132765/3 "2018-05-23T02:20:16Z")

</div>

Thanks for your reply. I run all the tests use one of nodes as coordinate node that get above results. and then switch to another node didn't change at all, and also gc is stable.

---

<div class="post-metadata">

**Author:** ![ans76](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ans76/32/31446_2.png) [@ans76](https://discuss.elastic.co/u/ans76)\
**Post date:** [May 23, 2018, 5:51am UTC](https://discuss.elastic.co/t/elasticsearch-same-query-has-different-performance/132765/4 "2018-05-23T05:51:32Z")

</div>

@eedugon There's one more thing, node n1 ping n2 cost 1.5ms on average, so does switch, any chance may network issue incurred?

---

<div class="post-metadata">

**Author:** ![eedugon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eedugon/32/45404_2.png) [@eedugon](https://discuss.elastic.co/u/eedugon)\
**Post date:** [May 24, 2018, 2:23pm UTC](https://discuss.elastic.co/t/elasticsearch-same-query-has-different-performance/132765/5 "2018-05-24T14:23:36Z")

</div>

Hi @ans76,

About your network concern, I don't believe there's any problem with the `1.5ms` reply on average, but it could be.  
Anyway the topic is interesting, I would suggest to do the following tests:

- Do the searches with profile activated, to see where exactly the time is being consumed, and check the differences between the short and long ones.  
- [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-profile.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-profile.html)
- Try to force the search to use local data when possible instead of finding the data in the shards of other nodes (just for investigation purposes, to see if we get always the same response time when we ask the node to return all the data from itself. In a real traffic case I wouldn't recommend to use the `preferred_local` option).  
- [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-preference.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-preference.html)
- Check with an index of 4 shards instead of 5.

Regards!  
Eduardo

---

<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:** [June 21, 2018, 2:23pm UTC](https://discuss.elastic.co/t/elasticsearch-same-query-has-different-performance/132765/6 "2018-06-21T14:23:42Z")

</div>

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