# Sorting performance trouble

**URL:** <https://discuss.elastic.co/t/sorting-performance-trouble/27809>\
**Category:** Elasticsearch\
**Created:** [August 21, 2015, 12:06am UTC](https://discuss.elastic.co/t/sorting-performance-trouble/27809 "2015-08-21T00:06:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![liamwhite](https://avatars.discourse-cdn.com/v4/letter/l/ccd318/32.png) [@liamwhite](https://discuss.elastic.co/u/liamwhite)\
**Post date:** [August 21, 2015, 12:06am UTC](https://discuss.elastic.co/t/sorting-performance-trouble/27809/1 "2015-08-21T00:06:35Z")

</div>

Hi,

Recently we moved to a new production server and upgraded from ES 1.4.1 to 1.7.1 in the process.

Since the upgrade, sorting performance on an entire collection (comments) to return the top 5 newest documents with 4 million documents has decreased a good deal from 75ms average to 175ms average, as well as a 3x slowdown on queries on the images index (~1 million documents) from 50ms to 150ms.

To attempt to determine if it was a regression in 1.7.1, I cloned the comments index to a local instance of ES 1.7.1 and attempted to sort using the same query and config file as production; performance was around 70ms for matching/sorting all documents and returning the top 5.

Almost the only differences in the config file are naming (ElasticSearch =\> Elasticsearch) and indentation (# commented thing =\> #commented thing); the two seem functionally identical.

Any ideas of suggestions on what to poke on production would be very helpful.

FWIW, the query is here:

```
{
  "index": "comments",
  "type": "comment",
  "body": {
    "query": {
      "filtered": {
        "query": {"match_all": {}},
        "filter": {
          "term": {"hidden_from_users": "false", "_cache": "true" }
        }
      }
    },
    "sort": [{"posted_at": "desc"}],
    "size": 5,
    "from": 0
  }
}
```

---

<div class="post-metadata">

**Author:** ![Norberto\_Meijome](https://avatars.discourse-cdn.com/v4/letter/n/ed655f/32.png) [@Norberto\_Meijome](https://discuss.elastic.co/u/Norberto_Meijome)\
**Post date:** [August 21, 2015, 5:14am UTC](https://discuss.elastic.co/t/sorting-performance-trouble/27809/2 "2015-08-21T05:14:55Z")

</div>

Hi Liam,  
Everything else is the same between your prod env and your local instance?  
( io subsystem, CPU, ram, #queries...)

---

<div class="post-metadata">

**Author:** ![liamwhite](https://avatars.discourse-cdn.com/v4/letter/l/ccd318/32.png) [@liamwhite](https://discuss.elastic.co/u/liamwhite)\
**Post date:** [August 21, 2015, 4:44pm UTC](https://discuss.elastic.co/t/sorting-performance-trouble/27809/3 "2015-08-21T16:44:12Z")

</div>

CPU and RAM are different:  
Local is an Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz with 24GB of RAM  
Production is a Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz with 128GB of RAM

Both have more than enough memory to fit the entire comments index (645mb, no \_source or \_all) into memory.

I didn't measure by number of queries, simply average execution time. While I didn't test that this is the case, it is possible that on production Elastic is busy doing other things when receiving the comments load+sort query. I suppose I can bring a short site downtime to test this, if you think that might be the issue.

---

<div class="post-metadata">

**Author:** ![liamwhite](https://avatars.discourse-cdn.com/v4/letter/l/ccd318/32.png) [@liamwhite](https://discuss.elastic.co/u/liamwhite)\
**Post date:** [August 22, 2015, 12:09am UTC](https://discuss.elastic.co/t/sorting-performance-trouble/27809/4 "2015-08-22T00:09:34Z")

</div>

I brought the site down temporarily to test whether the issue was concurrent requests; once the site was off, query performance did not change.

---

<div class="post-metadata">

**Author:** ![Harlin\_ES](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@Harlin\_ES](https://discuss.elastic.co/u/Harlin_ES)\
**Post date:** [August 25, 2015, 10:56pm UTC](https://discuss.elastic.co/t/sorting-performance-trouble/27809/5 "2015-08-25T22:56:42Z")

</div>

How much memory are you dedicating to ES?

---

<div class="post-metadata">

**Author:** ![liamwhite](https://avatars.discourse-cdn.com/v4/letter/l/ccd318/32.png) [@liamwhite](https://discuss.elastic.co/u/liamwhite)\
**Post date:** [August 26, 2015, 12:30am UTC](https://discuss.elastic.co/t/sorting-performance-trouble/27809/6 "2015-08-26T00:30:59Z")

</div>

On production, 31.5 gigabytes.

It's only using 18.

---

<div class="post-metadata">

**Author:** ![ksenji](https://avatars.discourse-cdn.com/v4/letter/k/bb73d2/32.png) [@ksenji](https://discuss.elastic.co/u/ksenji)\
**Post date:** [August 26, 2015, 1:18am UTC](https://discuss.elastic.co/t/sorting-performance-trouble/27809/7 "2015-08-26T01:18:43Z")

</div>

Compare the node stats (/\_nodes/stats?pretty) on both environments to see if something stands out.

---

<div class="post-metadata">

**Author:** ![liamwhite](https://avatars.discourse-cdn.com/v4/letter/l/ccd318/32.png) [@liamwhite](https://discuss.elastic.co/u/liamwhite)\
**Post date:** [August 26, 2015, 2:05am UTC](https://discuss.elastic.co/t/sorting-performance-trouble/27809/8 "2015-08-26T02:05:54Z")

</div>

Here are the node stats on the old (idle) production server and the new (busy) production server, as well as a diff between them:

> <https://gist.github.com/liamwhite/6fb3dcb5fd338fafedbe>

---

<div class="post-metadata">

**Author:** ![Harlin\_ES](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@Harlin\_ES](https://discuss.elastic.co/u/Harlin_ES)\
**Post date:** [August 26, 2015, 4:28pm UTC](https://discuss.elastic.co/t/sorting-performance-trouble/27809/9 "2015-08-26T16:28:47Z")

</div>

Maybe try bringing that down to 30.5GB. I think that is recommended as the maximum in order to avoid 64 bit addresses.

---

<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, 11:53pm UTC](https://discuss.elastic.co/t/sorting-performance-trouble/27809/10 "2017-07-05T23:53:41Z")

</div>


