Search code examples
javaelasticsearchjvmhomebrewelasticsearch-2.4

Elasticsearch 2.4 jvm.options ignored on MacOS Mojave (Homebrew install)


I've installed ElasticSearch 2.4 on my mac via HomeBrew. I'm trying to see if I can increase the JVM heap size for ElasticSearch.

I changed the following lines (to set the heap size to 8 gigs) in /usr/local/etc/elasticsearch/jvm.options

-Xms8g
-Xmx8g

I then restart the service using brew services restart [email protected] and run curl localhost:9200/_nodes/stats/jvm?pretty to check the JVM size but I get back:

"mem" : {
      "heap_used_in_bytes" : 144690472,
      "heap_used_percent" : 13,
      "heap_committed_in_bytes" : 259522560,
      "heap_max_in_bytes" : 1038876672,
      "non_heap_used_in_bytes" : 62484680,
      "non_heap_committed_in_bytes" : 65093632,
      ...

Why are my Xms8g and Xmx8g flags being ignored in jvm.options, and what should I do to make elsaticsearch respect them?

I've been basing my actions on: How to change Elasticsearch max memory size


Solution

  • Figured it out!

    You need to change the environment variables passed through the plist used to launch elasticsearch.

    In /usr/local/Cellar/[email protected]/2.4.6/[email protected], under the <key>EnvironmentVariables</key> key, add:

    <dict>
      <key>ES_HEAP_SIZE</key>
      <string>2g</string>
    </dict>
    

    Beware, there's another plist that exists in ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch.plist. Changing this does nothing since it gets overwritten by brew services on restart.

    Also of note, there are two jvm.options files to do with ElasticSearch visible on your system:

    • /usr/local/Cellar/[email protected]/2.4.6/libexec/config

    • /usr/local/etc/elasticsearch/jvm.options

    It looks like one of these is just a symlink to the other, and changing the memory flags in either of them does absolutely nothing.