Tuning and Optimizing memory for Elasticsearch
Disabling all swap files
sudo swapoff -a
Configure swappiness by setting the sysctl value vm.swappiness is set to 1
vm.swappiness=1
Enable bootstrap.memory_lock, this locks the process address space into RAM, preventing any Elasticsearch heap memory from being swapped out
bootstrap.memory_lock: true
You should not allocate more than 50 % of the total RAM to the JVM heap size. Elasticsearch requires memory for purposes other than the JVM heap. For example, Elasticsearch uses off-heap buffers for efficient network communication and relies on the operating system’s filesystem cache for efficient access to files. The JVM itself also requires some memory.
We tend to think that the more the memory the better the performance. HEAP memory is an exception. In any case, the heap size 26GB should be safe in most of the systems but not be set to more than 30GB. The JVM uses HEAP memory for storing object pointers - Compressed Ordinary Object Pointer (OOP). Above 32 GB of HEAP, Java needs to use regular, 64-bit, pointers. Because a lot of space will be used by pointer itself it drastically decreases how many objects can be stored in HEAP. Around 50 GB of HEAP will be the same as around 30 GB.