Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Set Elasticsearch 5 Memory (Heap) Size When Running as a Service

In Elasticsearch 5.x running as a service, how do I set the memory (heap) size?

The environment variables

ES_MIN_MEM   ES_MAX_MEM    ES_HEAP_SIZE

are not being read or taken into account when Elasticsearch is started as a service through Systemd on Debian-based distros (Ubuntu, Mint, etc) using

sudo service elasticsearch start
like image 845
Phil B Avatar asked Mar 11 '23 09:03

Phil B


1 Answers

In ElasticSearch 5.x, after October 26, 2016 the old methods to set memory size do not work anymore.

For example: after changing ES_HEAP_SIZE in /etc/default/elasticsearch and in etc/init.d/elasticsearch, if you run ps aux | grep elasticsearch you will still get

/usr/bin/java -Xms2g -Xmx2g Meaning 2G min and 2G max RAM

You have to make the changes in

/etc/elasticsearch/jvm.options

Xms represents the initial size of total heap space
Xmx represents the maximum size of total heap space
so change them according to your needs, for example:

-Xms16g

-Xmx16g

Documentation on deciding the right size (still showing the old variable and file names at the time of writing)

the default setting in Elasticsearch 5 are -Xms2g -Xmx2g

like image 62
Phil B Avatar answered Apr 27 '23 17:04

Phil B