# Script groovy may cause memory leak in elastic v5.4

**URL:** <https://discuss.elastic.co/t/script-groovy-may-cause-memory-leak-in-elastic-v5-4/119407>\
**Category:** Elasticsearch\
**Created:** [February 12, 2018, 2:45am UTC](https://discuss.elastic.co/t/script-groovy-may-cause-memory-leak-in-elastic-v5-4/119407 "2018-02-12T02:45:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![1222kkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/1222kkk/32/23635_2.png) [@1222kkk](https://discuss.elastic.co/u/1222kkk)\
**Post date:** [February 12, 2018, 2:45am UTC](https://discuss.elastic.co/t/script-groovy-may-cause-memory-leak-in-elastic-v5-4/119407/1 "2018-02-12T02:45:57Z")

</div>

Recently, I found my elasticsearch cluster always get full gc every two days.

Cluster settings are as follows:  
es version: v2.3.2  
2 \* node, every node set 8G for es  
data size is just 500MB+ with 5 indices

I recognized that groovy memory leak issue may exist in v2.3.2.

[Groovy scripting - possible memory leak ES 2.3.3](https://github.com/elastic/elasticsearch/issues/19396)

So I try to reduce the use of `script` in `update` and user params instead if script lines have dynamic params.

Everything seems to goes well before `jstat -gcold` prints as follows:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/f/7f7e3daed8af081d2aa7f1c63a0a82dee45f1f9a.png)

I think full gc will finally comes since the use of old gc still increase.

So I try to update es version to v5.4.x. One days later, `org.codehaus.groovy.runtime.metaclass.MetaMethodIndex$Entry` still increase as v2.3.2.

```
num #instances #bytes class name
----------------------------------------------
   1: 459350 992735952 [B
   2: 547852 219588688 [C
   3: 1826845 102303320 org.codehaus.groovy.runtime.metaclass.MetaMethodIndex$Entry
   4: 1485050 62888720 [Ljava.lang.Object;
   5: 998557 31953824 java.util.HashMap$Node
   6: 1322667 31744008 org.codehaus.groovy.util.FastArray
   7: 146991 21167600 [Lorg.codehaus.groovy.util.ComplexKeyHashMap$Entry;
   8: 113728 14367840 [Ljava.util.HashMap$Node;
   9: 421638 13492416 org.wltea.analyzer.dic.DictSegment
  10: 529427 12706248 java.lang.String

```

Here is my question:

groovy memory leak is solved in es v2.4.0, why it seems doesn't work...  
Is there any best way to use `script` in update which may not result in cluster frequent full gc ?

Thank you!

---

<div class="post-metadata">

**Author:** ![1222kkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/1222kkk/32/23635_2.png) [@1222kkk](https://discuss.elastic.co/u/1222kkk)\
**Post date:** [February 26, 2018, 2:13am UTC](https://discuss.elastic.co/t/script-groovy-may-cause-memory-leak-in-elastic-v5-4/119407/2 "2018-02-26T02:13:21Z")

</div>

anyone face the same problem or any suggestions ?

---

<div class="post-metadata">

**Author:** ![1222kkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/1222kkk/32/23635_2.png) [@1222kkk](https://discuss.elastic.co/u/1222kkk)\
**Post date:** [February 26, 2018, 2:14am UTC](https://discuss.elastic.co/t/script-groovy-may-cause-memory-leak-in-elastic-v5-4/119407/3 "2018-02-26T02:14:48Z")

</div>

`jmap -histo:live`

```
 num #instances #bytes class name
----------------------------------------------
   1: 7023686 393326416 org.codehaus.groovy.runtime.metaclass.MetaMethodIndex$Entry
   2: 5403346 152118584 [Ljava.lang.Object;
   3: 5085873 122060952 org.codehaus.groovy.util.FastArray
   4: 2831417 90605344 java.util.HashMap$Node
   5: 565199 81389552 [Lorg.codehaus.groovy.util.ComplexKeyHashMap$Entry;
   6: 90390 78825856 [B
   7: 591953 66105088 [C
   8: 1332338 42634816 org.codehaus.groovy.util.SingleKeyHashMap$Entry
   9: 40378 41983392 [Lorg.codehaus.groovy.runtime.metaclass.MetaMethodIndex$Entry;
  10: 807474 38758752 java.lang.invoke.MethodHandleImpl$CountingWrapper
  11: 181720 32837448 [Ljava.util.HashMap$Node;
  12: 686366 27454640 java.lang.invoke.BoundMethodHandle$Species_LL
  13: 687156 21988992 java.util.concurrent.ConcurrentHashMap$Node
  14: 243943 21466984 java.lang.reflect.Method
  15: 417310 20199984 [I
  16: 403742 19379616 java.lang.invoke.BoundMethodHandle$Species_L4
  17: 605507 19376224 groovy.lang.MetaBeanProperty
  18: 397889 19098672 java.util.HashMap
  19: 203232 16258560 java.lang.reflect.Constructor
  20: 583558 14005392 java.lang.String
```

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [February 26, 2018, 4:37am UTC](https://discuss.elastic.co/t/script-groovy-may-cause-memory-leak-in-elastic-v5-4/119407/4 "2018-02-26T04:37:48Z")

</div>

I recommend you switch to using `painless` scripts (added in 5.0). It is unlikely anyone will look at debugging a `groovy` issue as it was removed in 6.0.

---

<div class="post-metadata">

**Author:** ![1222kkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/1222kkk/32/23635_2.png) [@1222kkk](https://discuss.elastic.co/u/1222kkk)\
**Post date:** [March 12, 2018, 8:43am UTC](https://discuss.elastic.co/t/script-groovy-may-cause-memory-leak-in-elastic-v5-4/119407/5 "2018-03-12T08:43:26Z")

</div>

Fine, I will try it.  
Now I temporarily solved the issue by using all params in label `params` instead of using them directly in script line and it worked.

---

<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 9, 2018, 8:43am UTC](https://discuss.elastic.co/t/script-groovy-may-cause-memory-leak-in-elastic-v5-4/119407/6 "2018-04-09T08:43:44Z")

</div>

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