Elasticsearch 内存占用高

Elastic search high memory consumption

Elastic 搜索占用了超过 25 GB 的 RAM。我为弹性搜索编制索引的数据大约为 1 GB。为什么弹性搜索需要这么多 space?

每当 Elastic Search 使用默认设置启动时,它会消耗大约 1 GB RAM,因为它们的堆 space 分配默认为 1GB 设置。

确保检查 "jvm.options" 文件

对于 Ubuntu Linux OS :- {如果使用 debian 文件安装} 文件位置:- /etc/elasticsearch/

对于 Windows OS :- File Location为解压后的文件夹位置 {extacted_folder_path/config/jvm.options}

在 jvm.options 文件中,您需要配置 JVM 堆的一些设置

-Xms1g

-Xmx1g

-Xms1g 设置为在弹性搜索启动时获取 1 GB 的初始 RAM 大小。 -Xmx1g 定义分配给 Elastic Search JVM 堆的最大 RAM。

您需要将这两个参数调整为 4 GB 或任何适合您需要的值。

-Xms4g

-Xmx4g

注意 :- 不要设置超过 32 GB Java 堆 Space 它不会带来任何好处。

出于某种原因,“elasticsearch”默认使用了我 24G 内存的 53%,如果你问我,这太疯狂了。可能是因为它是自动配置的,如下文所述。无论如何,要设置自定义 JVM 堆大小,应该在 jvm.options.d 目录中创建一个文件“jvm.options”并添加默认值“jvm.options”文件中所述的自定义值:

################################################################
## IMPORTANT: JVM heap size
################################################################
##
## The heap size is automatically configured by Elasticsearch
## based on the available memory in your system and the roles
## each node is configured to fulfill. If specifying heap is
## required, it should be done through a file in jvm.options.d,
## and the min and max should be set to the same value. For
## example, to set the heap to 4 GB, create a new file in the
## jvm.options.d directory containing these lines:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################

我已将内存使用量设置为 1G,因此文件如下所示:

-Xms1g
-Xmx1g

然后你应该重新启动“elasticsearch”服务,你可以检查内存使用情况:
sudo service elasticsearch status

Elasticsearch 和 jvm 版本:
版本:7.11.0,构建:default/deb/8ced7813d6f16d2ef30792e2fcde3e755795ee04/2021-02-08T22:44:01.320463Z,JVM:15.0.1