elasticsearch resource_error ai_generated partial

ElasticsearchException: [script_cache] eviction triggered, current heap usage [92%], max cache size [10000]

ID: elasticsearch/script-cache-eviction-memory-pressure

Also available as: JSON · Markdown · 中文
75%Fix Rate
82%Confidence
1Evidence
2024-06-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.17.14 active
8.11.0 active
8.14.0 active

Root Cause

The script cache is full and heap memory usage is high, causing Elasticsearch to evict compiled scripts to free memory, which degrades performance.

generic

中文

脚本缓存已满且堆内存使用率很高,导致Elasticsearch驱逐已编译的脚本以释放内存,从而降低性能。

Official Documentation

https://www.elastic.co/guide/en/elasticsearch/reference/current/circuit-breaker.html#script-compilation-circuit-breaker

Workarounds

  1. 80% success Increase the script cache size in elasticsearch.yml: script.cache.max_size: 20000 and restart nodes, or use dynamic setting: PUT _cluster/settings { "transient": { "script.cache.max_size": "20000" } }
    Increase the script cache size in elasticsearch.yml: script.cache.max_size: 20000 and restart nodes, or use dynamic setting: PUT _cluster/settings { "transient": { "script.cache.max_size": "20000" } }
  2. 90% success Reduce script variety by parameterizing inline scripts: use stored scripts or parameters instead of generating unique script sources per query, e.g., { "script": { "id": "my_script", "params": { "factor": 2 } } }
    Reduce script variety by parameterizing inline scripts: use stored scripts or parameters instead of generating unique script sources per query, e.g., { "script": { "id": "my_script", "params": { "factor": 2 } } }

中文步骤

  1. 在elasticsearch.yml中增加脚本缓存大小:script.cache.max_size: 20000并重启节点,或使用动态设置:PUT _cluster/settings { "transient": { "script.cache.max_size": "20000" } }
  2. 通过参数化内联脚本减少脚本种类:使用存储脚本或参数代替每次查询生成唯一脚本源,例如 { "script": { "id": "my_script", "params": { "factor": 2 } } }

Dead Ends

Common approaches that don't work:

  1. 60% fail

    Larger heap may delay eviction but does not fix the root cause of too many unique scripts being compiled; cache still fills up

  2. 90% fail

    Disabling the cache forces recompilation on every script execution, causing severe performance degradation and potential OOM