# Setting JVM Heap size for Elasticsearch container

**URL:** <https://discuss.elastic.co/t/setting-jvm-heap-size-for-elasticsearch-container/300374>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [March 22, 2022, 6:34pm UTC](https://discuss.elastic.co/t/setting-jvm-heap-size-for-elasticsearch-container/300374 "2022-03-22T18:34:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![userR](https://avatars.discourse-cdn.com/v4/letter/u/22d042/32.png) [@userR](https://discuss.elastic.co/u/userR)\
**Post date:** [March 22, 2022, 6:34pm UTC](https://discuss.elastic.co/t/setting-jvm-heap-size-for-elasticsearch-container/300374/1 "2022-03-22T18:34:37Z")

</div>

I recently ran into an error where my cluster would turn red due to exceeding the maximum allocated heap. Once it returned back to below the threshold, I saw that by default, only 512mb was allocated.

```auto
name id node.role heap.current heap.percent heap.max
es01 yzkn cdfhilmrstw 400.7mb 78 512mb

```

Checking my docker stats, I see:

```auto
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O          
kibana 0.61% 504 MiB / 1 GiB 49.22% 2.83 GB / 3.9 GB 0 B / 0 B          
elasticsearch 0.04% 998.1 MiB / 1 GiB 97.47% 580 MB / 234 MB 10.4 GB / 1.18 GB 

```

I plan on bind mounting my own jvm.options file to /usr/share/Elasticsearch/config/jvm.options.d/ (`- ./elasticsearch/config/jvm.options:/usr/share/elasticsearch/config/jvm.options.d/jvm.options` in my docker-compose file), but had a quick question on configuring this file.

As of now, my server has 32 GB of RAM, and I saw that the recommended amount is half of your total RAM. I plan to have the following settings in my jvm.options file:

```auto
-Xms16g
-Xmx16g

```

Would this maximize the memory usage on my Elasticsearch container? Are there any other suggested configuration changes?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 24, 2022, 8:21am UTC](https://discuss.elastic.co/t/setting-jvm-heap-size-for-elasticsearch-container/300374/2 "2022-03-24T08:21:37Z")

</div>

The getting started documentation also contains a paragraph about setting the heap size. See [Running the Elastic Stack ("ELK") on Docker | Getting Started [8.1] | Elastic](https://www.elastic.co/guide/en/elastic-stack-get-started/8.1/get-started-stack-docker.html#docker-enroll-nodes)

---

<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:** [April 21, 2022, 8:21am UTC](https://discuss.elastic.co/t/setting-jvm-heap-size-for-elasticsearch-container/300374/3 "2022-04-21T08:21:54Z")

</div>

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