0

I am trying to automatically set the heap size on my ElasticSearch v5.6.3 nodes (Ubuntu 16)

The machines are hosted on Azure and I want to do this so that when I scale up the machine, it automatically sets the heap size to an appropriate level without needing to manually open the /etc/elasticsearch/jvm.options file and set it and then restart the service.

As far as I can work out the suggested ways to set the heap size (in ElasticSearch 5) are:

  1. In the jvm.options file
  2. via the ES_JAVA_OPTS environment variable.

So it follows that if I run a script to set the ES_JAVA_OPTS at startup before the elasticsearch service starts.

I tried a lot of things to try and get the ES_JAVA_OPTS to be set but when looking at the logs I can see it was using the default.

I've tried various things:

  • editting the /etc/init.d/elasticsearch script and reinstalling the service
  • editting the elasticsearch-systemd-pre-exec to set the variable.
  • Setting the variable in rc.local

In the end, I have put a script in init.d and used the runlevel to execute it first.

The script updates the jvm.options file using sed like so:

#!/bin/bash
memoryInKb="$(awk '/MemTotal/ {print $2}' /proc/meminfo)"
heapSize="$(expr $memoryInKb / 1024 / 1000 / 2)"
sed -i "s/#*-Xmx[0-9]\+g/-Xmx${heapSize}g/g" /etc/elasticsearch/jvm.options
sed -i "s/#*-Xms[0-9]\+g/-Xms${heapSize}g/g" /etc/elasticsearch/jvm.options

But I think this is really dirty. There must be a nicer way of doing this?

I tried setting the ES_JAVA_OPTS in the same way but it didn't work.

My ultimate aim is make scaling up easier.

  • Any particular reason why you are not scaling out to more nodes at a constant size? There is a maximum recommended JVM heap memory although you might not be near that: https://docs.microsoft.com/en-us/azure/architecture/elasticsearch/#memory-requirements – John Mahowald Nov 01 '17 at 19:36
  • @JohnMahowald I'm trying to create a VM image that I can use in a Virtual Machine Scale Set. I may want to scale it up or use it in a test cluster which has less memory. – Rob Stevenson-Leggett Nov 02 '17 at 07:58

0 Answers0