# Why do the first few queries take much longer time to run than the rest?

**URL:** <https://discuss.elastic.co/t/why-do-the-first-few-queries-take-much-longer-time-to-run-than-the-rest/55386>\
**Category:** Elasticsearch\
**Created:** [July 13, 2016, 8:49am UTC](https://discuss.elastic.co/t/why-do-the-first-few-queries-take-much-longer-time-to-run-than-the-rest/55386 "2016-07-13T08:49:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![adityasinghraghav](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@adityasinghraghav](https://discuss.elastic.co/u/adityasinghraghav)\
**Post date:** [July 13, 2016, 8:49am UTC](https://discuss.elastic.co/t/why-do-the-first-few-queries-take-much-longer-time-to-run-than-the-rest/55386/1 "2016-07-13T08:49:51Z")

</div>

When I restart a node, for a simple match query the took time for the first two or three queries is much more than the following. I am trying to understand why it is that way. Is it because of some sort of caching and would it make sense to disable this caching process to run performance tests ?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 13, 2016, 9:09am UTC](https://discuss.elastic.co/t/why-do-the-first-few-queries-take-much-longer-time-to-run-than-the-rest/55386/2 "2016-07-13T09:09:47Z")

</div>

It does not make sense to run performance tests if you are not using all the power of the search engine?  
What do you want to measure then? What your user will see in production or the bad case?

Anyhow, yes there is some caching. Most of it is the Filesystem cache. Your OS is caching files which are read. Which is happening here behind the scene.  
Also some filter caches. It's automatically managed by elasticsearch.

---

<div class="post-metadata">

**Author:** ![adityasinghraghav](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@adityasinghraghav](https://discuss.elastic.co/u/adityasinghraghav)\
**Post date:** [July 13, 2016, 9:19am UTC](https://discuss.elastic.co/t/why-do-the-first-few-queries-take-much-longer-time-to-run-than-the-rest/55386/3 "2016-07-13T09:19:33Z")

</div>

The idea is to measure the worst case performance. I was thinking that if the cache is specific to a query, then it would make more sense to clear the cache to get an idea of how much time it would take when there's a query which has not been encountered before.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 13, 2016, 9:35am UTC](https://discuss.elastic.co/t/why-do-the-first-few-queries-take-much-longer-time-to-run-than-the-rest/55386/4 "2016-07-13T09:35:29Z")

</div>

You can read this: [https://www.elastic.co/guide/en/elasticsearch/reference/2.3/shard-request-cache.html#\_cache\_invalidation](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/shard-request-cache.html#_cache_invalidation)

---

<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:** [July 5, 2017, 10:36pm UTC](https://discuss.elastic.co/t/why-do-the-first-few-queries-take-much-longer-time-to-run-than-the-rest/55386/5 "2017-07-05T22:36:07Z")

</div>


