# How to set elasticsearch jvm heap size?

**URL:** https://discuss.elastic.co/t/how-to-set-elasticsearch-jvm-heap-size/261611
**Category:** Elasticsearch
**Created:** [January 20, 2021, 4:12am UTC](https://discuss.elastic.co/t/how-to-set-elasticsearch-jvm-heap-size/261611 "2021-01-20T04:12:19Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![wangxr1985](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wangxr1985/32/117798_2.png) [@wangxr1985](https://discuss.elastic.co/u/wangxr1985)
#### Post date: [January 20, 2021, 4:12am UTC](https://discuss.elastic.co/t/how-to-set-elasticsearch-jvm-heap-size/261611/1 "2021-01-20T04:12:19Z")

</div>

If I have a 16C64G machine and install CentOS7.6 on it, There is 62gb available memory.

```
             total used free shared buff/cache available
Mem: 62 34 0 0 27 27
Swap: 0 0 0

```

> **[Advanced configuration settings | Elasticsearch Reference \[7.x\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/advanced-configuration.html#setting-jvm-heap-size)**

According to the reference, I have 3 choices to set the jvm heap size:  
31.5gb: The largest size I can set If I want to use compressed object pointers (compressed oops)  
31gb: half of the system memory and use compressed object pointers (compressed oops)  
30gb: The largest size I can set if I want to use zero based compressed oops.

So which is the best practise?

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [January 20, 2021, 4:14am UTC](https://discuss.elastic.co/t/how-to-set-elasticsearch-jvm-heap-size/261611/2 "2021-01-20T04:14:53Z")

</div>

Half of the system, up to just under 32GB. You will want to check in your Elasticsearch logs at startup if it's using compressed pointers if you get near 31-32GB.

---

<div class="post-metadata">

### Author: ![wangxr1985](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wangxr1985/32/117798_2.png) [@wangxr1985](https://discuss.elastic.co/u/wangxr1985)
#### Post date: [January 20, 2021, 5:48am UTC](https://discuss.elastic.co/t/how-to-set-elasticsearch-jvm-heap-size/261611/3 "2021-01-20T05:48:05Z")

</div>

So you mean 31gb is the best,right?  
I want to know if it is worth to reduce 1gb memory, from 31gb to 30gb, to use zero based compressed oops.

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [January 20, 2021, 5:48am UTC](https://discuss.elastic.co/t/how-to-set-elasticsearch-jvm-heap-size/261611/4 "2021-01-20T05:48:43Z")

</div>

> [@wangxr1985](#):
>
> I want to know if it is worth to reduce 1gb memory, from 31gb to 30gb, to use zero based compressed oops.

It 100% is.  
Otherwise you need (from memory) about 40+ gig of heap to store the same amount.

---

<div class="post-metadata">

### Author: ![wangxr1985](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wangxr1985/32/117798_2.png) [@wangxr1985](https://discuss.elastic.co/u/wangxr1985)
#### Post date: [January 20, 2021, 5:53am UTC](https://discuss.elastic.co/t/how-to-set-elasticsearch-jvm-heap-size/261611/5 "2021-01-20T05:53:54Z")

</div>

Sorry I didn't express it clearly.  
I just want to compare zero based compressed oops with compressed oops, both of them(30gb and 31gb) use the compressed object pointers.

---

<div class="post-metadata">

### Author: ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)
#### Post date: [January 20, 2021, 8:24am UTC](https://discuss.elastic.co/t/how-to-set-elasticsearch-jvm-heap-size/261611/6 "2021-01-20T08:24:12Z")

</div>

The reference manual [contains clear instructions](https://www.elastic.co/guide/en/elasticsearch/reference/current/important-settings.html#heap-size-settings):

> Set `Xmx` and `Xms` to no more than the threshold for zero-based compressed oops.

You can ignore this instruction at your own risk, but if you want to know the recommended practice then that's what it is.

---

<div class="post-metadata">

### Author: ![wangxr1985](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wangxr1985/32/117798_2.png) [@wangxr1985](https://discuss.elastic.co/u/wangxr1985)
#### Post date: [January 20, 2021, 8:40am UTC](https://discuss.elastic.co/t/how-to-set-elasticsearch-jvm-heap-size/261611/7 "2021-01-20T08:40:31Z")

</div>

I know the threshold value of compressed oops and zero-based compressed oops.  
But I don't know which one is better.  
Theoretically zero-based compressed oops has better performance than compressed oops, but if I want to use it ,the largest value must be no more than 30gb. 1gb less than 31gb with compressed oops.

---

<div class="post-metadata">

### Author: ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)
#### Post date: [January 20, 2021, 8:56am UTC](https://discuss.elastic.co/t/how-to-set-elasticsearch-jvm-heap-size/261611/8 "2021-01-20T08:56:53Z")

</div>

> [@wangxr1985](#):
>
> But I don't know which one is better.

It's better to stick to what the manual says.

---

<div class="post-metadata">

### Author: ![wangxr1985](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wangxr1985/32/117798_2.png) [@wangxr1985](https://discuss.elastic.co/u/wangxr1985)
#### Post date: [January 20, 2021, 11:23am UTC](https://discuss.elastic.co/t/how-to-set-elasticsearch-jvm-heap-size/261611/9 "2021-01-20T11:23:36Z")

</div>

So 30gb is better, because it meets all recommendations in the manual, right?

---

<div class="post-metadata">

### Author: ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)
#### Post date: [January 20, 2021, 11:48am UTC](https://discuss.elastic.co/t/how-to-set-elasticsearch-jvm-heap-size/261611/10 "2021-01-20T11:48:51Z")

</div>

The exact threshold varies from JVM to JVM, I don't think 30GB is always low enough but it often is. As long as your JVM reports that it's using zero-based compressed oops, it's all good.

---

<div class="post-metadata">

### Author: ![wangxr1985](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wangxr1985/32/117798_2.png) [@wangxr1985](https://discuss.elastic.co/u/wangxr1985)
#### Post date: [January 20, 2021, 11:54am UTC](https://discuss.elastic.co/t/how-to-set-elasticsearch-jvm-heap-size/261611/11 "2021-01-20T11:54:57Z")

</div>

OK,thanks.

---

<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: [February 17, 2021, 11:55am UTC](https://discuss.elastic.co/t/how-to-set-elasticsearch-jvm-heap-size/261611/12 "2021-02-17T11:55:11Z")

</div>

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