# Jvm heap size - garbage collection

**URL:** https://discuss.elastic.co/t/jvm-heap-size-garbage-collection/103840
**Category:** Elasticsearch
**Created:** [October 13, 2017, 7:16am UTC](https://discuss.elastic.co/t/jvm-heap-size-garbage-collection/103840 "2017-10-13T07:16:00Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Patrik\_Soderstrom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrik_soderstrom/32/53928_2.png) [@Patrik\_Soderstrom](https://discuss.elastic.co/u/Patrik_Soderstrom)
#### Post date: [October 13, 2017, 7:16am UTC](https://discuss.elastic.co/t/jvm-heap-size-garbage-collection/103840/1 "2017-10-13T07:16:00Z")

</div>

Hi,  
I´m trying to optimize the jvm heap size for nodes in my cluster. Sadly or good now 🙂 First picture is heap size 4GB and second picture is 5GB. Which one looks best for garbage collection?

 ![Capture](https://us1.discourse-cdn.com/elastic/original/3X/3/0/30da91a1aebc1f2f7ff8605771c0675ab972caa3.PNG) ![Capture2](https://us1.discourse-cdn.com/elastic/original/3X/0/a/0a4d5d56d06767285758ef1d2f110e301386e96d.PNG)

Personally I think the last picture (5GB) looks best.

---

<div class="post-metadata">

### Author: ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)
#### Post date: [October 20, 2017, 6:08am UTC](https://discuss.elastic.co/t/jvm-heap-size-garbage-collection/103840/2 "2017-10-20T06:08:48Z")

</div>

Hi @Patrik_Soderstrom,

the first picture looks very untypical for Java applications. It is typically a sign that the heap is almost full and the garbage collector cannot free up a lot of memory. The second picture looks much healthier in that regard.

I just wonder whether the straight line at the top marks the reserved heap size (i.e. 4GB and 5GB respectively) or the total machine memory. I guess it's the latter but if it is the former I think you should investigate that strange behavior.

Daniel

---

<div class="post-metadata">

### Author: ![Patrik\_Soderstrom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrik_soderstrom/32/53928_2.png) [@Patrik\_Soderstrom](https://discuss.elastic.co/u/Patrik_Soderstrom)
#### Post date: [October 23, 2017, 1:10pm UTC](https://discuss.elastic.co/t/jvm-heap-size-garbage-collection/103840/3 "2017-10-23T13:10:22Z")

</div>

Hi @danielmitterdorfer,

the line in the top marks the max heap size (reserved).  
It sounds and looks like I should increase the heap size from 4 to 5 GB.  
What strange behavior do you see on the second picture?

Thanks for taking your time to answer.

Best regards,  
Patrik

---

<div class="post-metadata">

### Author: ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)
#### Post date: [October 23, 2017, 2:29pm UTC](https://discuss.elastic.co/t/jvm-heap-size-garbage-collection/103840/4 "2017-10-23T14:29:52Z")

</div>

Hi @Patrik_Soderstrom,

> [@Patrik\_Soderstrom](#):
>
> It sounds and looks like I should increase the heap size from 4 to 5 GB.

Yes.

> [@Patrik\_Soderstrom](#):
>
> What strange behavior do you see on the second picture?

The behavior as such is fine. But if you consider that the line at the top is 5GB, it looks to me as if CMS (the garbage collector that is used for the old generation) kicks in quite early, at around 50% heap utilization (hard to tell without y-axis labels) but by default it is configured to kick in at 75% heap utilization (as controlled by `-XX:CMSInitiatingOccupancyFraction=75`). Is it possible that the blue line is actually just showing the size of the old generation instead of total heap utilization? Then this picture would make sense to me.

Daniel

---

<div class="post-metadata">

### Author: ![Patrik\_Soderstrom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrik_soderstrom/32/53928_2.png) [@Patrik\_Soderstrom](https://discuss.elastic.co/u/Patrik_Soderstrom)
#### Post date: [October 24, 2017, 6:18am UTC](https://discuss.elastic.co/t/jvm-heap-size-garbage-collection/103840/5 "2017-10-24T06:18:41Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/6/6/664c64ea9a7380a951d6ae3e16d9f8ff997ba84e.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/3/83eca2a66d4bc372e4d0757482615c242278c86b.png)

Now you have the scales and full picture 🙂  
The top picture seems to do garbage collection after ~75%.  
And the bottom one also seems to be ~75%

So it even might be an idea to increase the 5GB limit to a higher number. I was not aware of the 75% limit. Or would you recommend me setting that limit higher?

---

<div class="post-metadata">

### Author: ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)
#### Post date: [October 24, 2017, 6:34am UTC](https://discuss.elastic.co/t/jvm-heap-size-garbage-collection/103840/6 "2017-10-24T06:34:45Z")

</div>

Hi @Patrik_Soderstrom,

> [@Patrik\_Soderstrom](#):
>
> Now you have the scales and full picture

That helps indeed. I have assumed that the y-axis starts at zero not at 2.8 GB. Everything's fine here and you shouldn't change `-XX:CMSInitiatingOccupancyFraction`.

Daniel

---

<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: [November 21, 2017, 6:34am UTC](https://discuss.elastic.co/t/jvm-heap-size-garbage-collection/103840/7 "2017-11-21T06:34:55Z")

</div>

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