title: Deploying Elasticsearch on ecs fargate - HeapDumpOnOutOfMemoryError
body: <p>I am trying to deploy elasticsearch on AWS ECS fargate service. I have successfully deployed a version of elasticsearch with flag <code>discovery.type=single-node</code> and that works fine without any issue, but this has certain memory limitations and I cannot use it for prod.</p>
  <p>Next step I got rid of the flag <code>discovery.type=single-node</code> set the following env variable via the task definition on AWS console <code>ES_HEAP_SIZE=10g</code> of the heap size. Also I have assigned <code>8GB</code> of memory to the task and the same to the container and <code>2vCPUs</code>.</p>
  <p>I am getting few errors:</p>
  <ul>
  <li><code>HeapDumpOnOutOfMemoryError</code></li>
  </ul>
  <pre><code>{&quot;type&quot;: &quot;server&quot;, &quot;timestamp&quot;: &quot;2022-05-01T14:10:45,376Z&quot;, &quot;level&quot;: &quot;INFO&quot;, &quot;component&quot;: &quot;o.e.n.Node&quot;, &quot;cluster.name&quot;: &quot;docker-cluster&quot;, &quot;node.name&quot;: &quot;ip-172-31-10-153.eu-central-1.compute.internal&quot;, &quot;message&quot;: &quot;JVM arguments [-Xshare:auto, -Des.networkaddress.cache.ttl=60, -Des.networkaddress.cache.negative.ttl=10, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -XX:+ShowCodeDetailsInExceptionMessages, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dio.netty.allocator.numDirectArenas=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.locale.providers=SPI,COMPAT, --add-opens=java.base/java.io=ALL-UNNAMED, -XX:+UseG1GC, -Djava.io.tmpdir=/tmp/elasticsearch-18437358607495407146, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m, -Des.cgroups.hierarchy.override=/, -Xms4096m, -Xmx4096m, -XX:MaxDirectMemorySize=2147483648, -XX:G1HeapRegionSize=4m, -XX:InitiatingHeapOccupancyPercent=30, -XX:G1ReservePercent=15, -Des.path.home=/usr/share/elasticsearch, -Des.path.conf=/usr/share/elasticsearch/config, -Des.distribution.flavor=default, -Des.distribution.type=docker, -Des.bundled_jdk=true]&quot; }
  </code></pre>
  <ul>
  <li><code>max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]</code></li>
  <li><code>max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]</code></li>
  </ul>
  <p>I tried different approaches like <code>nofile=65535:65535</code>, <code>memlock</code> but didn't work for me.</p>