JVM settingsedit

Configure JVM settings in the jvm.options settings file. JVM settings can also be set via the LS_JAVA_OPTS environment variable.

This file contains a line-delimited list of JVM arguments following a special syntax:

  • lines consisting of whitespace only are ignored
  • lines beginning with # are treated as comments and are ignored

    # this is a comment
  • lines beginning with a - are treated as a JVM option that applies independent of the version of the JVM

    -Xmx2g
  • lines beginning with a number followed by a : followed by a - are treated as a JVM option that applies only if the version of the JVM matches the number

    8:-Xmx2g
  • lines beginning with a number followed by a - followed by a : are treated as a JVM option that applies only if the version of the JVM is greater than or equal to the number

    8-:-Xmx2g
  • lines beginning with a number followed by a - followed by a number followed by a : are treated as a JVM option that applies only if the version of the JVM falls in the inclusive range of the two numbers

    8-9:-Xmx2g
  • all other lines are rejected

Setting the JVM heap sizeedit

Here are some tips for adjusting the JVM heap size:

  • The recommended heap size for typical ingestion scenarios should be no less than 4GB and no more than 8GB.
  • CPU utilization can increase unnecessarily if the heap size is too low, resulting in the JVM constantly garbage collecting. You can check for this issue by doubling the heap size to see if performance improves.
  • Do not increase the heap size past the amount of physical memory. Some memory must be left to run the OS and other processes. As a general guideline for most installations, don’t exceed 50-75% of physical memory. The more memory you have, the higher percentage you can use.
  • Set the minimum (Xms) and maximum (Xmx) heap allocation size to the same value to prevent the heap from resizing at runtime, which is a very costly process.
  • You can make more accurate measurements of the JVM heap by using either the jmap command line utility distributed with Java or by using VisualVM. For more info, see Profiling the Heap.

Setting the off-heap sizeedit

The operating system, persistent queue mmap pages, direct memory, and other processes require memory in addition to memory allocated to heap size. Keep the overall memory requirements in mind when you allocate memory.

By default, a JVM’s off-heap direct memory limit is the same as the heap size. Check out beats input memory usage. Consider setting -XX:MaxDirectMemorySize to half of the heap size.

Setting the JVM stack sizeedit

Large configurations may require additional JVM stack memory. If you see a stack overflow error, try increasing the JVM stack size. Add an entry similar to this one in the jvm.options settings file:

-Xss4M

Note that the default stack size is different per platform and per OS flavor. You can find out what the default is by running:

java -XX:+PrintFlagsFinal -version | grep ThreadStackSize

Depending on the default stack size, start by multiplying by 4x, then 8x, and then 16x until the overflow error resolves.

Using LS_JAVA_OPTSedit

The LS_JAVA_OPTS environment variable can also be used to override JVM settings in the jvm.options file settings file. The content of this variable is additive to options configured in the jvm.options file, and will override any settings that exist in both places.

For example to set a different locale to launch Logstash instance:

LS_JAVA_OPTS="-Duser.country=DE -Duser.language=de" bin/logstash -e 'input { stdin { codec => json } }'