Elasticsearch Settings Best Practices – Bootstrap Memory Lock Setting is Set to False



Elasticsearch Settings Best Practices – Bootstrap Memory Lock Setting is Set to False

Opster Team

July 2020, Version: 1.7-7.9


In addition to reading this guide, run the free Elasticsearch Health Check-Up. Get actionable recommendations that can improve performance and prevent incidents (does not require any installation). Among the dozens of checks included are: shards sizes, search errors, thread pools, management queue size, circuit breakers and many more. Join over 700 users who use this free tool.

What Does it Mean

Elasticsearch performance can be heavily penalised if the node is allowed to swap memory to disk. Elasticsearch can be configured to automatically prevent memory swapping on its host machine by adding the bootstrap memory_lock true setting to elasticsearch.yml. If bootstrap checks are enabled, Elasticsearch will not start if memory swapping is not disabled. You can learn more about bootstrap checks here: Bootstraps Check in Elasticsearch – A Detailed Guide With Examples.

Note: It may be perfectly valid to have 

bootstrap.memory_lock: false

In your configuration if you have taken alternative steps to stop memory swapping.  See Other ways of Preventing Memory Swapping below.

How To Fix It

Edit elasticsearch.yml to include the following setting:

bootstrap.memory_lock: true

You can check whether the setting has worked by running:

GET _nodes?filter_path=**.mlockall

You should see true in the output.

{
  "nodes" : {
"ifU4SFrKTcCaR5Om0uFFbw" : {
  "process" : {
    "mlockall" : true
  }
}
  }
}

If on the other hand you see false, then further configuration is necessary.

RPM and Debian SystemD Installations

sudo systemctl edit elasticsearch 

Add the following:

[Service]
LimitMEMLOCK=infinity
sudo systemctl daemon-reload

.zip and .tar.gz Installations

Add the following line to  /etc/security/limits.conf

elasticsearch  -  nofile  65535

Other Ways of Preventing Memory Swapping

There are other ways of preventing memory swapping other than using 

bootstrap.memory_lock: false
Turn Off all Swapping on Linux Option 1
sudo swapoff -a

This doesn’t require a restart of Elasticsearch.

To disable permanently (upon restart) edit /etc/fstab file

Comment out any lines containing “swap” below is just an example

#/dev/mapper/ubuntu--vg-swap_1 none        swap sw          0  
Turn Off all Swapping on Linux using sysctl Option 2

Edit /etc/sysctl.conf

vm.swappiness=1

Checking Memory Swapping is Effective

Run:

GET _nodes/stats/os

You should see the following in the response for each of the nodes:

"swap" : {
      "total_in_bytes" : 0,
      "free_in_bytes" : 0,
      "used_in_bytes" : 0
    },




Improve Elasticsearch Performance

Run The Analysis