Elasticsearch is packed with new features to help you build the best search solutions for your use case. Dive into our sample notebooks to learn more, start a free cloud trial, or try Elastic on your local machine now.
Elasticsearch memory requirements
The Elasticsearch process is very memory intensive. Elasticsearch uses a JVM (Java Virtual Machine), and best practices recommend allocating close to 50% of the memory available on a node to the JVM. The JVM relies on memory so that the Lucene process can access index values very fast. The other 50% is left to the file system cache which keeps data that is regularly accessed in memory.
For a full explanation of JVM memory management, read this blog. It is also common to receive warnings from the different types of circuit breakers.
jvm.mem
The most important memory section is the JVM heap.
The output looks like this:
Note that the heap_used_in_bytes in a healthy JVM will follow a saw tooth pattern due to the garbage collection process, increasing steadily up to around 70%, then reducing sharply to 30% when garbage collection occurs.
The JVM heap_max_in_bytes will depend on the value set in jvm.options file, and you should set it to be 50% of the RAM available for your container or server.
For more information on JVM heap issues, please see: Heap size usage and JVM garbage collection in Elasticsearch.
Explaining the different types of memory statistics
When looking at the memory statistics, we need to be aware that many Elasticsearch applications are running inside containers on much larger machines. This is typical if you are using a hosted service such as AWs Elasticsearch service or Elastic cloud, or if you are running Elasticsearch on Docker or Kubernetes. In such cases, it’s important to be careful to interpret the memory statistics available to us.
There are various memory statistics available from the Elasticsearch monitoring APIs, as explained below:
The above statistics are for a development node running on docker. Let’s interpret the sections we received here:
os.mem
The first section “os.mem” refers to the host server where the machine is running. In this case we are running on Docker, so 16GB refers to the memory of the host machine where the container is running. Note that it is quite normal for a machine to be using close to 100% of its memory, and this does not indicate a problem.
os.swap
The “os.swap” section again refers to the host machine. In this case, we can see that the host machine allows swapping. This is quite normal when we are running a container inside a host with swapping still enabled. We can double check that inside the Docker container no swap is permitted by running:
os.cgroup
Finally, we can see the “os.cgroup” section which refers to the container itself. In this case the container is using 4GB of memory.
process.mem
We also have access to a statistic virtual memory:
Note that “process.total_virtual_in_bytes” includes the entire memory available to the process, including virtual memory available via mmap.