# What causes JVM memory to be high?

**URL:** <https://discuss.elastic.co/t/what-causes-jvm-memory-to-be-high/54062>\
**Category:** Elasticsearch\
**Created:** [June 27, 2016, 5:12pm UTC](https://discuss.elastic.co/t/what-causes-jvm-memory-to-be-high/54062 "2016-06-27T17:12:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![esamudio](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@esamudio](https://discuss.elastic.co/u/esamudio)\
**Post date:** [June 27, 2016, 5:12pm UTC](https://discuss.elastic.co/t/what-causes-jvm-memory-to-be-high/54062/1 "2016-06-27T17:12:31Z")

</div>

Whenever I look at the stats of my cluster on Marvel, over time, JVM usage gets really high. I have a few questions:

What causes the JVM memory usage to gradually increase?

Why does the cluster tend to become unresponsive when it gets too high? I personally thought that if it has resources, it should be good to use 100% of them.

---

<div class="post-metadata">

**Author:** ![Dilip\_Kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dilip_kumar/32/15459_2.png) [@Dilip\_Kumar](https://discuss.elastic.co/u/Dilip_Kumar)\
**Post date:** [June 27, 2016, 5:27pm UTC](https://discuss.elastic.co/t/what-causes-jvm-memory-to-be-high/54062/2 "2016-06-27T17:27:56Z")

</div>

You should uninstall Marvel.. Actually Marvel Always create index for each index..That takes server space...so avoid Marvel then check...

---

<div class="post-metadata">

**Author:** ![esamudio](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@esamudio](https://discuss.elastic.co/u/esamudio)\
**Post date:** [June 27, 2016, 5:58pm UTC](https://discuss.elastic.co/t/what-causes-jvm-memory-to-be-high/54062/3 "2016-06-27T17:58:11Z")

</div>

How much of an effect can Marvel have?

I have 16 gb of ram (allocating 8 to ES\_HEAP), 20 nodes, mlockall set to true and swapoff on all the machines.

---

<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:** [June 29, 2016, 12:22am UTC](https://discuss.elastic.co/t/what-causes-jvm-memory-to-be-high/54062/4 "2016-06-29T00:22:33Z")

</div>

> [@Dilip\_Kumar](#):
>
> You should uninstall Marvel.. Actually Marvel Always create index for each index..That takes server space...so avoid Marvel then check...

What? No.  
Use [Elasticsearch Curator](https://www.elastic.co/guide/en/elasticsearch/client/curator/current/index.html) to clean up older data automatically if you don't need it.  
Also, using Marvel can show you the cause of this.

> [@esamudio](#):
>
> What causes the JVM memory usage to gradually increase?

Depends, it can be queries or increases in datasets or many things.  
Can you provide more info on your cluster, sizing, version etc.

---

<div class="post-metadata">

**Author:** ![esamudio](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@esamudio](https://discuss.elastic.co/u/esamudio)\
**Post date:** [June 29, 2016, 1:37pm UTC](https://discuss.elastic.co/t/what-causes-jvm-memory-to-be-high/54062/5 "2016-06-29T13:37:29Z")

</div>

@warkolm

My cluster has 20 data nodes(20 primary shards, 2 replicas), 1 client and 1 master.

Elasticsearch version: 2.3.3

Marvel version: 2.3.0

JVM version: 1.8.0\_91

OS version: Ubuntu 14.04

I have mlockall set to true, ran "sudo swapoff -a" on the entire cluster. I'm allocating 16 gb of ram in each node (8gb for ES\_HEAP\_SIZE).

When I first posted this, I was experiencing a mapper parsing exception due to a bug in the ES output plugin in logstash. This caused the GC to not work (or work incredibly slow to the point the node (and cluster) became unresponsive). As of right now, the log doesn't show me any errors other than the occasional "marvel.agent uncaught thread exception" which doesn't seem to have much of an effect.

I've been ingesting a back log of data I lost in a cluster failure for the past 12 hours. Currently at 132,942,626 documents, 124GB total data, Memory: 118GB / 171GB. My data nodes are constantly sitting at 75% JVM memory usage at this point.

I also have this settings in the log and they're still not producing any more information:  
`{"persistent":{},"transient":{"logger":{"index":{"indexing":{"slowlog":"DEBUG"},"search":{"slowlog":"DEBUG"}}}}}`

Here's a gist of the output of: curl '[http://localhost:9200/\_nodes/stats?pretty&human](http://localhost:9200/_nodes/stats?pretty&human)''  
[gist](https://gist.github.com/esamudio/a7a4aceea60a0fd486a1ba2995a76d1f)

Is it normal for the JVM memory usage to be constantly hitting those metrics? Ideally, I would be running queries while indexing, is that attainable? RIght now, there seems to be a high amount of memory usage by indexing/updating (I perform both).

---

<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:** [June 30, 2016, 1:50am UTC](https://discuss.elastic.co/t/what-causes-jvm-memory-to-be-high/54062/6 "2016-06-30T01:50:07Z")

</div>

> [@esamudio](#):
>
> My cluster has 20 data nodes(20 primary shards, 2 replicas), 1 client and 1 master.

Why 2 replicas?  
And one master is bad as well, see [Important Configuration Changes | Elasticsearch: The Definitive Guide [2.x] | Elastic](https://www.elastic.co/guide/en/elasticsearch/guide/2.x/important-configuration-changes.html#_minimum_master_nodes)

---

<div class="post-metadata">

**Author:** ![esamudio](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@esamudio](https://discuss.elastic.co/u/esamudio)\
**Post date:** [June 30, 2016, 1:53am UTC](https://discuss.elastic.co/t/what-causes-jvm-memory-to-be-high/54062/7 "2016-06-30T01:53:17Z")

</div>

> [@warkolm](#):
>
> Why 2 replicas?

I will definitely look at the link and increase the number of master nodes. As for the replicas, it's in case of cluster failure? As in, a VM not being recovered after any sort of failure.

Thanks for the help by the way!

---

<div class="post-metadata">

**Author:** ![Dilip\_Kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dilip_kumar/32/15459_2.png) [@Dilip\_Kumar](https://discuss.elastic.co/u/Dilip_Kumar)\
**Post date:** [June 30, 2016, 7:36am UTC](https://discuss.elastic.co/t/what-causes-jvm-memory-to-be-high/54062/8 "2016-06-30T07:36:26Z")

</div>

RAM is ok for u and ur server is only have es ..if u view indices u will see list of indices with big size unnecessary... only because of Marvel.. So delete those indices created by Marvel and check it..

---

<div class="post-metadata">

**Author:** ![rmuir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rmuir/32/44949_2.png) [@rmuir](https://discuss.elastic.co/u/rmuir)\
**Post date:** [July 4, 2016, 2:33pm UTC](https://discuss.elastic.co/t/what-causes-jvm-memory-to-be-high/54062/9 "2016-07-04T14:33:40Z")

</div>

Somehow, you are compiling lots of scripts over and over:

```
  "script" : {
    "compilations" : 140018,
    "cache_evictions" : 139918
  }

```

These classes are not ever unloaded (see [https://github.com/elastic/elasticsearch/issues/18572](https://github.com/elastic/elasticsearch/issues/18572))

```
    "classes" : {
      "current_loaded_count" : 151826,
      "total_loaded_count" : 151950,
      "total_unloaded_count" : 124
    }

```

Don't send a unique new script for every request: instead, make use of script `params` for the part that changes.

---

<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:** [July 5, 2017, 10:38pm UTC](https://discuss.elastic.co/t/what-causes-jvm-memory-to-be-high/54062/10 "2017-07-05T22:38:30Z")

</div>


