elasticsearch resource_error ai_generated partial

Elasticsearch异常:[脚本缓存] 驱逐触发,当前堆使用率[92%],最大缓存大小[10000]

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

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

其他格式: JSON · Markdown 中文 · English
75%修复率
82%置信度
1证据数
2024-06-10首次发现

版本兼容性

版本状态引入弃用备注
7.17.14 active
8.11.0 active
8.14.0 active

根因分析

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

English

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

generic

官方文档

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

解决方案

  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 } } }

无效尝试

常见但无效的做法:

  1. 60% 失败

    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% 失败

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