How to check ES_HEAP_SIZE

Hi guys,

I tried to setting ES_HEAP_SIZE to 1024m on my linux server. I used this setting > export ES_HEAP_SIZE=1024m. Now how to check if this new setting is work??

Thanks

check echo $ES_HEAP_SIZE

set it in elasticsearch.yml of config file

What do you mean by setting es_heap_size on config file?? I read on the elasticsearch website that es_heap_size is an environment variable. and how to setting it to config file?? ES_HEAP_SIZE : 1024m like this??

Thanks

I tried to setting ES_HEAP_SIZE to 1024m on my linux server. I used this setting > export ES_HEAP_SIZE=1024m. Now how to check if this new setting is work??

Look at the resulting JVM process when you start ES, specifically the -Xmx option.

If you're starting ES as a service (which you should be doing) you should probably be modifying /etc/sysconfig/elasticsearch or /etc/default/elasticsearch instead.

2 Likes

Both Elasticsearch and the JVM provides some wonderful introspection tools, so there are many ways to check this.

  • Query the endpoint /_nodes/stats/jvm and for each node inspect the path jvm.mem.heap_max_in_bytes. For example, if I start Elasticsearch with ES_HEAP_SIZE=4g listening on localhost and then execute
curl -sS -XGET localhost:9200/_nodes/stats/jvm | jq '..|.heap_max_in_bytes?|select(type != "null")'

I see

4225236992
  • Similarly, you can use the cat nodes API by executing
curl -sS -XGET "localhost:9200/_cat/nodes?h=heap*&v"

which would give

heap.current heap.percent heap.max 
     119.9mb            2    3.9gb 

with the same 4g heap.

on the console. If you have multiple nodes running, this will print out one line for each node.

  • You can use jps to see the command line flags. For example, if I start Elasticsearch with ES_HEAP_SIZE=4g and then execute
jps -l -m -v

then I see

5858 org.elasticsearch.bootstrap.eElasticsearche start -Xms4g -Xmx4g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/Users/jason/elasticsearch/elasticsearch-2.1.0
  • Another good tool to know is jinfo. For example:
jinfo -flags 5858

gives

Attaching to process ID 5858, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.66-b17
Non-default VM flags: -XX:CICompilerCount=4 -XX:CMSInitiatingOccupancyFraction=75 -XX:+DisableExplicitGC -XX:+HeapDumpOnOutOfMemoryError -XX:InitialHeapSize=4294967296 -XX:MaxHeapSize=4294967296 -XX:MaxNewSize=697892864 -XX:MaxTenuringThreshold=6 -XX:MinHeapDeltaBytes=196608 -XX:NewSize=697892864 -XX:OldPLABSize=16 -XX:OldSize=3597074432 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseFastUnorderedTimeStamps -XX:+UseParNewGC 
Command line:  -Xms4g -Xmx4g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/Users/jason/elasticsearch/elasticsearch-2.1.0

Note the -XX:InitialHeapSize=4294967296 -XX:MaxHeapSize=4294967296 in the output.

There are many other ways to check this same information (JVisualVM, Java Mission Control, jstat, jmap, etc.).

4 Likes

That won't work though! See @magnusbaeck's response.