Skip to content

Instantly share code, notes, and snippets.

@dominicsayers
Last active March 2, 2024 15:52
Show Gist options
  • Star 86 You must be signed in to star a gist
  • Fork 21 You must be signed in to fork a gist
  • Save dominicsayers/8319752 to your computer and use it in GitHub Desktop.
Save dominicsayers/8319752 to your computer and use it in GitHub Desktop.
Configuring ElasticSearch to use less memory

What I actually did

/etc/security/limits.conf

elasticsearch hard memlock 100000

/etc/default/elasticsearch

ES_HEAP_SIZE=128m
MAX_LOCKED_MEMORY=100000
ES_JAVA_OPTS=-server

/etc/elasticsearch/elasticsearch.yml

index.number_of_shards: 1
index.number_of_replicas: 0

Advice I read

http://blog.lavoie.sl/2012/09/configure-elasticsearch-on-a-single-host.html (for an old version)

Edit /etc/security/limits.conf and add: elasticsearch hard memlock 100000

Edit the init script: /etc/init.d/elasticsearch
Change ES_HEAP_SIZE to 10-20% of your machine, I used 128m
Change MAX_LOCKED_MEMORY to 100000 Be sure to set it at the same value as 1.1
Change JAVA_OPTS to "-server"

Edit the config file: /etc/elasticsearch/elasticsearch.yml
index.number_of_shards: 1
index.number_of_replicas: 0
index.term_index_interval: 256
index.term_index_divisor: 5
network.host: 127.0.0.1
network.tcp.block: true

http://stackoverflow.com/questions/18132719/how-to-change-elasticsearch-max-size

	/etc/security/limits.conf:
	elasticsearch - nofile 65535
	elasticsearch - memlock unlimited

	/etc/default/elasticsearch:
	ES_HEAP_SIZE=512m
	MAX_OPEN_FILES=65535
	MAX_LOCKED_MEMORY=unlimited

	/etc/elasticsearch/elasticsearch.yml:
	bootstrap.mlockall: true
@breim
Copy link

breim commented Nov 6, 2014

Hey, thx bro

@chapinb
Copy link

chapinb commented Apr 19, 2015

👍

Thanks!

I also found adding a swap to help as well: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

@kyv
Copy link

kyv commented May 8, 2015

nice

@colegatron
Copy link

You should NEVER add swap to a Elasticsearch node. It will slow down the node.

@pat-humphreys
Copy link

FYI the path for /etc/default/elasticsearch has changed to /etc/sysconfig/elasticsearch
I am using 1.7.3

@MysteryDragon
Copy link

I'm using 2.2.0, everything is fine with /etc/default/elasticsearch, ES installed by DEB package in Ubuntu, and from Arch official repository in ArchLinux.

@pavarotti305
Copy link

Why when I enable bootstrap.mlockall: true on /etc/elasticsearch/elasticsearch.yaml directly my connection is refused

@adamcrown
Copy link

FYI apparently much of this no longer applies in version >= 5. I found this helpful https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html .

@tencentemr
Copy link

thanx a lot. This really help me with a low memory server only 400MB left for ES.
Before this, i set jvm options max heap size 300MB for ES,but it always goes up to 560MB and cause server Crash.
Now its lower to 323 MB. very nice.

@SBarkovskiy
Copy link

Thanks for the guidance! Nowadays - working very well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment