# ElasticSearch Inline script compilation circuit breaker triggered on static script code

**URL:** <https://discuss.elastic.co/t/elasticsearch-inline-script-compilation-circuit-breaker-triggered-on-static-script-code/277228>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [June 28, 2021, 12:37pm UTC](https://discuss.elastic.co/t/elasticsearch-inline-script-compilation-circuit-breaker-triggered-on-static-script-code/277228 "2021-06-28T12:37:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anver\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anver_s/32/46385_2.png) [@Anver\_S](https://discuss.elastic.co/u/Anver_S)\
**Post date:** [June 28, 2021, 12:37pm UTC](https://discuss.elastic.co/t/elasticsearch-inline-script-compilation-circuit-breaker-triggered-on-static-script-code/277228/1 "2021-06-28T12:37:34Z")

</div>

Using java rest api I submit bulk update requests with painless script

```auto
for (entry in params.entrySet()) {ctx._source[entry.getKey()] = entry.getValue();}

```

Occasionally I get dynamic compilation circuit breaker triggering on such updates.

Considering it is the only script we use I fail to understand why it would not compile once and get cached.

I am on rather old version of ES 7.2.0

---

<div class="post-metadata">

**Author:** ![Anver\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anver_s/32/46385_2.png) [@Anver\_S](https://discuss.elastic.co/u/Anver_S)\
**Post date:** [July 2, 2021, 3:36pm UTC](https://discuss.elastic.co/t/elasticsearch-inline-script-compilation-circuit-breaker-triggered-on-static-script-code/277228/2 "2021-07-02T15:36:54Z")

</div>

I've changed the script to be stored in hopes it would be compiled once. But even stored script fails with dynamic compilation circuit breaker exception.

```auto
Elasticsearch exception [type=illegal_argument_exception, reason=failed to execute script]","caused_by":{"type":"exception","reason":"Elasticsearch excepti
on [type=general_script_exception, reason=Failed to compile stored script [replace_field_values] using lang [painless]]","caused_by":{"type":"exception","reason":"Elasticsearch exception [type=circuit_breaking_exception, reason=[script] Too many dynamic script compilations
within, max: [75/5m]; please use indexed, or scripts with parameters instead; this limit can be changed by the [script.max_compilations_rate] setting]","durability":"TRANSIENT"}}},"status":400}]

```

---

<div class="post-metadata">

**Author:** ![Anver\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anver_s/32/46385_2.png) [@Anver\_S](https://discuss.elastic.co/u/Anver_S)\
**Post date:** [July 2, 2021, 8:31pm UTC](https://discuss.elastic.co/t/elasticsearch-inline-script-compilation-circuit-breaker-triggered-on-static-script-code/277228/3 "2021-07-02T20:31:44Z")

</div>

Apparently well behaved stored scripts can suffer from being evicted from cache and requiring compilation by other not so well behaved scripts. I did hope that stored scripts would be isolated in that regard but no such luck.

My service is using stored scripts and they were evicted by dynamically generated scripts from a different service on shared ElasticSearch instance. Cache limits per client would do the trick too. Oh well.

---

<div class="post-metadata">

**Author:** ![Anver\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anver_s/32/46385_2.png) [@Anver\_S](https://discuss.elastic.co/u/Anver_S)\
**Post date:** [July 6, 2021, 2:48pm UTC](https://discuss.elastic.co/t/elasticsearch-inline-script-compilation-circuit-breaker-triggered-on-static-script-code/277228/4 "2021-07-06T14:48:33Z")

</div>

I assume cache churn is caused by using simple LRUCache - I wonder if Window TinyLFU (W-TinyLFU) eviction policy would give you a better result - well behaved scripts will not be affected by poorly designed dynamic scripts.  
Solr has already switched to use [GitHub - ben-manes/caffeine: A high performance caching library for Java](https://github.com/ben-manes/caffeine) as default recommended cache due to better caching stats

---

<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:** [August 3, 2021, 2:49pm UTC](https://discuss.elastic.co/t/elasticsearch-inline-script-compilation-circuit-breaker-triggered-on-static-script-code/277228/5 "2021-08-03T14:49:13Z")

</div>

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