2017-12-12 10:24:37 -05:00
|
|
|
[[heap-size]]
|
2020-10-19 12:59:44 -04:00
|
|
|
[discrete]
|
|
|
|
=== Heap size settings
|
2017-12-12 10:24:37 -05:00
|
|
|
|
2020-10-19 12:59:44 -04:00
|
|
|
By default, {es} tells the JVM to use a heap with a minimum and maximum
|
2017-12-12 10:24:37 -05:00
|
|
|
size of 1 GB. When moving to production, it is important to configure heap size
|
2020-10-19 12:59:44 -04:00
|
|
|
to ensure that {es} has enough heap available.
|
2017-12-12 10:24:37 -05:00
|
|
|
|
2020-10-19 12:59:44 -04:00
|
|
|
{es} will assign the entire heap specified in
|
2017-12-12 10:24:37 -05:00
|
|
|
<<jvm-options,jvm.options>> via the `Xms` (minimum heap size) and `Xmx` (maximum
|
2020-11-02 09:22:49 -05:00
|
|
|
heap size) settings. These two settings must be equal to each other.
|
2017-12-12 10:24:37 -05:00
|
|
|
|
2019-05-15 09:26:04 -04:00
|
|
|
The value for these settings depends on the amount of RAM available on your
|
2019-05-10 08:55:27 -04:00
|
|
|
server:
|
2017-12-12 10:24:37 -05:00
|
|
|
|
2019-05-10 08:55:27 -04:00
|
|
|
* Set `Xmx` and `Xms` to no more than 50% of your physical RAM. {es} requires
|
|
|
|
memory for purposes other than the JVM heap and it is important to leave
|
|
|
|
space for this. For instance, {es} uses off-heap buffers for efficient
|
|
|
|
network communication, relies on the operating system's filesystem cache for
|
|
|
|
efficient access to files, and the JVM itself requires some memory too. It is
|
|
|
|
normal to observe the {es} process using more memory than the limit
|
|
|
|
configured with the `Xmx` setting.
|
2017-12-12 10:24:37 -05:00
|
|
|
|
2019-05-10 08:55:27 -04:00
|
|
|
* Set `Xmx` and `Xms` to no more than the threshold that the JVM uses for
|
2020-10-19 12:59:44 -04:00
|
|
|
compressed object pointers (compressed oops). The exact threshold varies but
|
|
|
|
is near 32 GB. You can verify that you are under the threshold by looking for a line in the logs like the following:
|
2017-12-12 10:24:37 -05:00
|
|
|
+
|
2020-10-19 12:59:44 -04:00
|
|
|
[source,txt]
|
|
|
|
----
|
|
|
|
heap size [1.9gb], compressed ordinary object pointers [true]
|
|
|
|
----
|
2017-12-12 10:24:37 -05:00
|
|
|
|
2020-10-19 12:59:44 -04:00
|
|
|
* Set `Xmx` and `Xms` to no more than the threshold for zero-based
|
|
|
|
compressed oops. The exact threshold varies but 26 GB is safe on most
|
|
|
|
systems and can be as large as 30 GB on some systems. You can verify that
|
2019-05-10 08:55:27 -04:00
|
|
|
you are under this threshold by starting {es} with the JVM options
|
|
|
|
`-XX:+UnlockDiagnosticVMOptions -XX:+PrintCompressedOopsMode` and looking for
|
|
|
|
a line like the following:
|
2017-12-12 10:24:37 -05:00
|
|
|
+
|
2020-10-19 12:59:44 -04:00
|
|
|
[source,txt]
|
|
|
|
----
|
|
|
|
heap address: 0x000000011be00000, size: 27648 MB, zero based Compressed Oops
|
|
|
|
----
|
|
|
|
+
|
|
|
|
This line shows that zero-based compressed oops are enabled. If zero-based
|
|
|
|
compressed oops are not enabled, you'll see a line like the following instead:
|
|
|
|
+
|
|
|
|
[source,txt]
|
|
|
|
----
|
|
|
|
heap address: 0x0000000118400000, size: 28672 MB, Compressed Oops with base: 0x00000001183ff000
|
|
|
|
----
|
2017-12-12 10:24:37 -05:00
|
|
|
|
2019-05-10 08:55:27 -04:00
|
|
|
The more heap available to {es}, the more memory it can use for its internal
|
|
|
|
caches, but the less memory it leaves available for the operating system to use
|
|
|
|
for the filesystem cache. Also, larger heaps can cause longer garbage
|
|
|
|
collection pauses.
|
|
|
|
|
2020-02-08 18:50:14 -05:00
|
|
|
Here is an example of how to set the heap size via a `jvm.options.d/` file:
|
2017-12-12 10:24:37 -05:00
|
|
|
|
|
|
|
[source,txt]
|
|
|
|
------------------
|
|
|
|
-Xms2g <1>
|
|
|
|
-Xmx2g <2>
|
|
|
|
------------------
|
|
|
|
<1> Set the minimum heap size to 2g.
|
|
|
|
<2> Set the maximum heap size to 2g.
|
|
|
|
|
2020-10-28 08:49:31 -04:00
|
|
|
Using `jvm.options.d` is the preferred method for configuring the heap size for
|
|
|
|
production deployments.
|
|
|
|
|
|
|
|
It is also possible to set the heap size via the `ES_JAVA_OPTS` environment
|
|
|
|
variable. This is generally discouraged for production deployments but is useful
|
|
|
|
for testing because it overrides all other means of setting JVM options.
|
2017-12-12 10:24:37 -05:00
|
|
|
|
|
|
|
[source,sh]
|
|
|
|
------------------
|
|
|
|
ES_JAVA_OPTS="-Xms2g -Xmx2g" ./bin/elasticsearch <1>
|
|
|
|
ES_JAVA_OPTS="-Xms4000m -Xmx4000m" ./bin/elasticsearch <2>
|
|
|
|
------------------
|
|
|
|
<1> Set the minimum and maximum heap size to 2 GB.
|
|
|
|
<2> Set the minimum and maximum heap size to 4000 MB.
|
|
|
|
|
|
|
|
NOTE: Configuring the heap for the <<windows-service,Windows service>> is
|
2019-05-10 08:55:27 -04:00
|
|
|
different than the above. The values initially populated for the Windows
|
|
|
|
service can be configured as above but are different after the service has been
|
2017-12-12 10:24:37 -05:00
|
|
|
installed. Consult the <<windows-service,Windows service documentation>> for
|
|
|
|
additional details.
|