# Why should we set -Xms and -Xmx to be equal to each other for Elasticsearch?

**URL:** <https://discuss.elastic.co/t/why-should-we-set-xms-and-xmx-to-be-equal-to-each-other-for-elasticsearch/189619>\
**Category:** Elasticsearch\
**Created:** [July 9, 2019, 8:09pm UTC](https://discuss.elastic.co/t/why-should-we-set-xms-and-xmx-to-be-equal-to-each-other-for-elasticsearch/189619 "2019-07-09T20:09:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![imrimt](https://avatars.discourse-cdn.com/v4/letter/i/76d3ee/32.png) [@imrimt](https://discuss.elastic.co/u/imrimt)\
**Post date:** [July 9, 2019, 8:09pm UTC](https://discuss.elastic.co/t/why-should-we-set-xms-and-xmx-to-be-equal-to-each-other-for-elasticsearch/189619/1 "2019-07-09T20:09:04Z")

</div>

We are currently on version 6.4 of Elasticsearch, and the documentation [here](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/heap-size.html#heap-size) recommends to set max and min heap size to be equal to each other. I'd like to understand what's the reasoning behind this.

One behavior we are noticing is that if the heap size is somewhere close to 26gb or 30gb, it can take up to a few minutes for the cluster to (re)start because the JVM needs to allocate the entire heap size right at the beginning. Hence, we want to know what the implications are if we set the -Xms setting to something like 50% of -Xmx.

---

<div class="post-metadata">

**Author:** ![surlysmiles](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@surlysmiles](https://discuss.elastic.co/u/surlysmiles)\
**Post date:** [July 12, 2019, 7:08am UTC](https://discuss.elastic.co/t/why-should-we-set-xms-and-xmx-to-be-equal-to-each-other-for-elasticsearch/189619/2 "2019-07-12T07:08:12Z")

</div>

I'm also very curious about this. It seems to defeat the purpose of memory scalability that the JVM provides which I guess can provide more consistent performance or behaviour. I'm not sure but would be very curious for an elastic engineer to reply to this.

---

<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 12, 2019, 8:10am UTC](https://discuss.elastic.co/t/why-should-we-set-xms-and-xmx-to-be-equal-to-each-other-for-elasticsearch/189619/3 "2019-07-12T08:10:05Z")

</div>

That's very common in production for any related Java Application.  
You want to allocate the whole memory from the start.

---

<div class="post-metadata">

**Author:** ![HenningAndersen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henningandersen/32/48188_2.png) [@HenningAndersen](https://discuss.elastic.co/u/HenningAndersen)\
**Post date:** [July 12, 2019, 12:32pm UTC](https://discuss.elastic.co/t/why-should-we-set-xms-and-xmx-to-be-equal-to-each-other-for-elasticsearch/189619/4 "2019-07-12T12:32:25Z")

</div>

Hi @imrimt ,

> up to a few minutes

how many nodes is that for? If it is for just one node, I would suspect that you were memory pressured on the node. The OS may have to flush out data to disk to make room for the JVM. It is normally advisable to have 64GB RAM to use such heap sizes, since you also need plenty RAM for file system cache.

Setting min and max to the same value in combination with `-XX:+AlwaysPreTouch` ensures that you take any penalty in memory allocation during node startup and not during node operation. Otherwise you risk getting a hit during search or indexing in case the JVM decides to expand its memory. Also, allowing the JVM to shrink heap by setting min != max you risk seeing this hit regularly.

---

<div class="post-metadata">

**Author:** ![imrimt](https://avatars.discourse-cdn.com/v4/letter/i/76d3ee/32.png) [@imrimt](https://discuss.elastic.co/u/imrimt)\
**Post date:** [July 12, 2019, 2:03pm UTC](https://discuss.elastic.co/t/why-should-we-set-xms-and-xmx-to-be-equal-to-each-other-for-elasticsearch/189619/5 "2019-07-12T14:03:12Z")

</div>

@HenningAndersen Thanks for the detailed answer. Yes, we are running on a 104GB machine with only one node, and the OS has around 17GB headroom (there are other processes running as well). So it's understandable that it can take sometime to allocate 26-30GB for the JVM.

What I'm more interested about is also addressed in your second point. Thanks!

---

<div class="post-metadata">

**Author:** ![jonathan\_rowe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonathan_rowe/32/49275_2.png) [@jonathan\_rowe](https://discuss.elastic.co/u/jonathan_rowe)\
**Post date:** [July 12, 2019, 2:27pm UTC](https://discuss.elastic.co/t/why-should-we-set-xms-and-xmx-to-be-equal-to-each-other-for-elasticsearch/189619/6 "2019-07-12T14:27:34Z")

</div>

you might want to see if you have transparent huge pages enabled, on RHEL6 this causes big startup delays and weve disabled it

---

<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, 2019, 2:27pm UTC](https://discuss.elastic.co/t/why-should-we-set-xms-and-xmx-to-be-equal-to-each-other-for-elasticsearch/189619/7 "2019-08-09T14:27:39Z")

</div>

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