Skip to content

Commit 2f2605b

Browse files
authored
[DOCS] Edit JVM settings info. Closes elastic#72259 (elastic#72350) (elastic#72435)
* [DOCS] Edit JVM settings info. Closes elastic#72259 * Apply suggestions from code review Co-authored-by: James Rodewig <[email protected]> * Incorporated review feedback.
1 parent b81ec61 commit 2f2605b

21 files changed

+166
-178
lines changed

docs/reference/redirects.asciidoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,3 +1501,8 @@ See <<getting-started>>.
15011501
=== Where to go from here
15021502

15031503
See <<getting-started>>.
1504+
1505+
[role="exclude",id="jvm-options"]
1506+
=== Settng JVM options
1507+
1508+
See <<set-jvm-options>>.

docs/reference/setup.asciidoc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ include::setup/install.asciidoc[]
4141

4242
include::setup/configuration.asciidoc[]
4343

44-
include::setup/jvm-options.asciidoc[]
44+
include::setup/important-settings.asciidoc[]
45+
4546

4647
include::setup/secure-settings.asciidoc[]
4748

@@ -96,11 +97,7 @@ include::modules/threadpool.asciidoc[]
9697
include::settings/notification-settings.asciidoc[]
9798

9899
include::setup/advanced-configuration.asciidoc[]
99-
100-
include::setup/important-settings.asciidoc[]
101-
102100
include::setup/sysconfig.asciidoc[]
103-
104101
include::setup/bootstrap-checks.asciidoc[]
105102

106103
include::setup/bootstrap-checks-xes.asciidoc[]
Lines changed: 124 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,138 @@
11
[[advanced-configuration]]
2-
=== Advanced configuration settings
2+
=== Advanced configuration
33

4-
The settings below are considered advanced and for expert users only. In
5-
most cases the {es}-provided default settings should be used. Take caution
6-
when modifying these settings as this could result in undesired behavior or
7-
reduced system performance.
4+
Modifying advanced settings is generally not recommended and could negatively
5+
impact performance and stability. Using the {es}-provided defaults
6+
is recommended in most circumstances.
87

9-
[[setting-jvm-heap-size]]
10-
==== Setting JVM heap size
8+
[[set-jvm-options]]
9+
==== Set JVM options
1110

12-
If you need to override the default <<heap-size-settings,heap size settings>>,
13-
follow the best practices below.
11+
If needed, you can override the default JVM options by adding custom options
12+
files (preferred) or setting the `ES_JAVA_OPTS` environment variable.
1413

15-
{es} assigns the entire heap specified in
16-
<<jvm-options,jvm.options>> via the `Xms` (minimum heap size) and `Xmx` (maximum
17-
heap size) settings. These two settings must be equal to each other.
14+
JVM options files must have the suffix '.options' and contain a line-delimited
15+
list of JVM arguments. JVM processes options files in lexicographic order.
1816

19-
The value for these settings depends on the amount of RAM available on your
20-
server:
17+
Where you put the JVM options files depends on the type of installation:
2118

22-
* Set `Xmx` and `Xms` to no more than 50% of your total system memory. {es} requires
23-
memory for purposes other than the JVM heap and it is important to leave
24-
space for this. For instance, {es} uses off-heap buffers for efficient
25-
network communication, relies on the operating system's filesystem cache for
26-
efficient access to files, and the JVM itself requires some memory too. It is
27-
normal to observe the {es} process using more memory than the limit
19+
* tar.gz or .zip: Add custom JVM options files to `config/jvm.options.d/`.
20+
* Debian or RPM: Add custom JVM options files to `/etc/elasticsearch/jvm.options.d/`.
21+
* Docker: Bind mount custom JVM options files into
22+
`/usr/share/elasticsearch/config/jvm.options.d/`.
23+
24+
NOTE: Do not modify the root `jvm.options` file. Use JVM options files instead.
25+
26+
[[jvm-options-syntax]]
27+
===== JVM options syntax
28+
29+
A JVM options file contains a line-delimited list of JVM arguments.
30+
Arguments are preceded by a dash (`-`).
31+
To apply the setting to specific versions, prepend the version
32+
or a range of versions followed by a colon.
33+
34+
* Apply a setting to all versions:
35+
+
36+
[source,text]
37+
-------------------------------------
38+
-Xmx2g
39+
-------------------------------------
40+
41+
* Apply a setting to a specific version:
42+
+
43+
[source,text]
44+
-------------------------------------
45+
8:-Xmx2g
46+
-------------------------------------
47+
48+
* Apply a setting to a range of versions:
49+
+
50+
[source,text]
51+
-------------------------------------
52+
8-9:-Xmx2g
53+
-------------------------------------
54+
+
55+
To apply a setting to a specific version and any later versions,
56+
omit the upper bound of the range.
57+
For example, this setting applies to Java 8 and later:
58+
+
59+
[source,text]
60+
-------------------------------------
61+
8-:-Xmx2g
62+
-------------------------------------
63+
64+
Blank lines are ignored. Lines beginning with `#` are treated as comments
65+
and ignored. Lines that aren't commented out and aren't recognized
66+
as valid JVM arguments are rejected and {es} will fail to start.
67+
68+
[[jvm-options-env]]
69+
===== Use environment variables to set JVM options
70+
71+
In production, use JVM options files to override the
72+
default settings. In testing and development environments,
73+
you can also set JVM options through the `ES_JAVA_OPTS` environment variable.
74+
75+
[source,sh]
76+
---------------------------------
77+
export ES_JAVA_OPTS="$ES_JAVA_OPTS -Djava.io.tmpdir=/path/to/temp/dir"
78+
./bin/elasticsearch
79+
---------------------------------
80+
81+
If you're using the RPM or Debian packages, you can specify
82+
`ES_JAVA_OPTS` in the <<sysconfig,system configuration file>>.
83+
84+
NOTE: {es} ignores the `JAVA_TOOL_OPTIONS` and `JAVA_OPTS` environment variables.
85+
86+
[[set-jvm-heap-size]]
87+
==== Set the JVM heap size
88+
89+
By default, {es} automatically sets the JVM heap size based on a node's
90+
<<node-roles,roles>> and total memory.
91+
Using the default sizing is recommended for most production environments.
92+
93+
NOTE: Automatic heap sizing requires the <<jvm-version,bundled JDK>> or, if using
94+
a custom JRE location, a Java 14 or later JRE.
95+
96+
To override the default heap size, set the minimum and maximum heap size
97+
settings, `Xms` and `Xmx`. The minimum and maximum values must be the same.
98+
99+
The heap size should be based on the available RAM:
100+
101+
* Set `Xms` and `Xmx` to no more than 50% of your total memory. {es} requires
102+
memory for purposes other than the JVM heap. For example, {es} uses
103+
off-heap buffers for efficient network communication and relies
104+
on the operating system's filesystem cache for
105+
efficient access to files. The JVM itself also requires some memory. It's
106+
normal for {es} to use more memory than the limit
28107
configured with the `Xmx` setting.
108+
+
109+
NOTE: When running in a container, such as <<docker,Docker>>, total memory is
110+
defined as the amount of memory visible to the container, not the total system
111+
memory on the host.
29112

30-
* Set `Xmx` and `Xms` to no more than the threshold that the JVM uses for
31-
compressed object pointers (compressed oops). The exact threshold varies but
32-
is near 32 GB. You can verify that you are under the threshold by looking for a line in the logs like the following:
113+
* Set `Xms` and `Xmx` to no more than 32 GB, the approximate threshold for
114+
compressed ordinary object pointers (oops). To verify you are under the
115+
threshold, check `elasticsearch.logs` for an entry like this:
33116
+
34117
[source,txt]
35118
----
36119
heap size [1.9gb], compressed ordinary object pointers [true]
37120
----
38121

39-
* Set `Xmx` and `Xms` to no more than the threshold for zero-based
122+
* Set `Xms` and `Xmx` to no more than the threshold for zero-based
40123
compressed oops. The exact threshold varies but 26GB is safe on most
41124
systems and can be as large as 30GB on some systems. You can verify that
42125
you are under this threshold by starting {es} with the JVM options
43-
`-XX:+UnlockDiagnosticVMOptions -XX:+PrintCompressedOopsMode` and looking for
44-
a line like the following:
126+
`-XX:+UnlockDiagnosticVMOptions -XX:+PrintCompressedOopsMode` and checking
127+
`elasticsearch.logs` for an entry like this:
45128
+
46129
[source,txt]
47130
----
48131
heap address: 0x000000011be00000, size: 27648 MB, zero based Compressed Oops
49132
----
50133
+
51-
This line shows that zero-based compressed oops are enabled. If zero-based
52-
compressed oops are not enabled, you'll see a line like the following instead:
134+
This entry shows that zero-based compressed oops are enabled. If zero-based
135+
compressed oops are not enabled, the entry looks like this:
53136
+
54137
[source,txt]
55138
----
@@ -61,31 +144,27 @@ caches. This leaves less memory for the operating system to use
61144
for the filesystem cache. Larger heaps can also cause longer garbage
62145
collection pauses.
63146

64-
Here is an example of how to set the heap size via a `jvm.options.d/` file:
147+
To configure the heap size, add the `Xms` and `Xmx` JVM arguments to a
148+
custom JVM options file with the extension `.options` and
149+
store it in the `jvm.options.d/` directory.
150+
For example, to set the maximum heap size to 2GB, set both `Xms` and `Xmx` to `2g`:
65151

66152
[source,txt]
67153
------------------
68-
-Xms2g <1>
69-
-Xmx2g <2>
154+
-Xms2g
155+
-Xmx2g
70156
------------------
71-
<1> Set the minimum heap size to 2g.
72-
<2> Set the maximum heap size to 2g.
73-
74-
In production, we recommend using `jvm.options.d` to configure heap sizes.
75157

76158
For testing, you can also set the heap sizes using the `ES_JAVA_OPTS`
77-
environment variable. The `ES_JAVA_OPTS` variable overrides all other JVM
78-
options. We do not recommend using `ES_JAVA_OPTS` in production.
159+
environment variable:
79160

80161
[source,sh]
81162
------------------
82-
ES_JAVA_OPTS="-Xms2g -Xmx2g" ./bin/elasticsearch <1>
83-
ES_JAVA_OPTS="-Xms4000m -Xmx4000m" ./bin/elasticsearch <2>
163+
ES_JAVA_OPTS="-Xms2g -Xmx2g" ./bin/elasticsearch
84164
------------------
85-
<1> Set the minimum and maximum heap size to 2 GB.
86-
<2> Set the minimum and maximum heap size to 4000 MB.
87165

88-
NOTE: Configuring the heap for the <<windows-service,Windows service>> is
89-
different than the above. The values initially populated for the Windows
90-
service can be configured as above but are different after the service has been
91-
installed. See <<windows-service>>.
166+
The `ES_JAVA_OPTS` variable overrides all other JVM
167+
options. We do not recommend using `ES_JAVA_OPTS` in production.
168+
169+
NOTE: If you are running {es} as a Windows service, you can change the heap size
170+
using the service manager. See <<windows-service>>.

docs/reference/setup/bootstrap-checks.asciidoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ bootstrap checks (either by not binding transport to an external interface, or
5757
by binding transport to an external interface and setting the discovery type to
5858
`single-node`). For this situation, you can force execution of the bootstrap
5959
checks by setting the system property `es.enforce.bootstrap.checks` to `true`
60-
(set this in <<jvm-options>>, or by adding `-Des.enforce.bootstrap.checks=true`
61-
to the environment variable `ES_JAVA_OPTS`). We strongly encourage you to do
60+
in the <<set-jvm-options,JVM options>>. We strongly encourage you to do
6261
this if you are in this specific situation. This system property can be used to
6362
force execution of the bootstrap checks independent of the node configuration.
6463

docs/reference/setup/configuration.asciidoc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[settings]]
2-
== Configuring Elasticsearch
2+
== Configuring {es}
33

4-
Elasticsearch ships with good defaults and requires very little configuration.
4+
{es} ships with good defaults and requires very little configuration.
55
Most settings can be changed on a running cluster using the
66
<<cluster-update-settings>> API.
77

@@ -13,11 +13,11 @@ able to join a cluster, such as `cluster.name` and `network.host`.
1313
[discrete]
1414
=== Config files location
1515

16-
Elasticsearch has three configuration files:
16+
{es} has three configuration files:
1717

18-
* `elasticsearch.yml` for configuring Elasticsearch
19-
* `jvm.options` for configuring Elasticsearch JVM settings
20-
* `log4j2.properties` for configuring Elasticsearch logging
18+
* `elasticsearch.yml` for configuring {es}
19+
* `jvm.options` for configuring {es} JVM settings
20+
* `log4j2.properties` for configuring {es} logging
2121

2222
These files are located in the config directory, whose default location depends
2323
on whether or not the installation is from an archive distribution (`tar.gz` or
@@ -96,7 +96,7 @@ node.name: ${HOSTNAME}
9696
network.host: ${ES_NETWORK_HOST}
9797
--------------------------------------------------
9898

99-
Values for environment variables must be simple strings. Use a comma-separated string to provide values that Elasticsearch will parse as a list. For example, Elasticsearch will split the following string into a list of values for the `${HOSTNAME}` environment variable:
99+
Values for environment variables must be simple strings. Use a comma-separated string to provide values that {es} will parse as a list. For example, {es} will split the following string into a list of values for the `${HOSTNAME}` environment variable:
100100

101101
[source,yaml]
102102
----

docs/reference/setup/important-settings.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[[important-settings]]
2-
== Important Elasticsearch configuration
2+
=== Important {es} configuration
33

44
{es} requires very little configuration to get started, but there are a number
55
of items which *must* be considered before using your cluster in production:

docs/reference/setup/important-settings/cluster-name.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[[cluster-name]]
22
[discrete]
3-
=== Cluster name setting
3+
==== Cluster name setting
44

55
A node can only join a cluster when it shares its `cluster.name` with all the
66
other nodes in the cluster. The default name is `elasticsearch`, but you should

docs/reference/setup/important-settings/discovery-settings.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[[discovery-settings]]
22
[discrete]
3-
=== Discovery and cluster formation settings
3+
==== Discovery and cluster formation settings
44

55
Configure two important discovery and cluster formation settings before going
66
to production so that nodes in the cluster can discover each other and elect a
77
master node.
88

99
[discrete]
1010
[[unicast.hosts]]
11-
==== `discovery.seed_hosts`
11+
===== `discovery.seed_hosts`
1212

1313
Out of the box, without any network configuration, {es} will bind to
1414
the available loopback addresses and scan local ports `9300` to `9305` to
@@ -44,7 +44,7 @@ dynamically.
4444

4545
[discrete]
4646
[[initial_master_nodes]]
47-
==== `cluster.initial_master_nodes`
47+
===== `cluster.initial_master_nodes`
4848

4949
When you start an {es} cluster for the first time, a
5050
<<modules-discovery-bootstrap-cluster,cluster bootstrapping>> step
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[[error-file-path]]
22
[discrete]
3-
=== JVM fatal error log setting
3+
==== JVM fatal error log setting
44

55
By default, {es} configures the JVM to write fatal error logs
66
to the default logging directory. On <<rpm,RPM>> and <<deb,Debian>> packages,
@@ -9,4 +9,4 @@ directory is located under the root of the {es} installation.
99

1010
These are logs produced by the JVM when it encounters a fatal error, such as a
1111
segmentation fault. If this path is not suitable for receiving logs,
12-
modify the `-XX:ErrorFile=...` entry in <<jvm-options,`jvm.options`>>.
12+
modify the `-XX:ErrorFile=...` entry in <<set-jvm-options,`jvm.options`>>.

docs/reference/setup/important-settings/es-tmpdir.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[[es-tmpdir]]
22
[discrete]
3-
=== Temporary directory settings
3+
==== Temporary directory settings
44

55
By default, {es} uses a private temporary directory that the startup
66
script creates immediately below the system temporary directory.

docs/reference/setup/important-settings/gc-logging.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[[gc-logging]]
22
[discrete]
3-
=== GC logging settings
3+
==== GC logging settings
44

55
By default, {es} enables garbage collection (GC) logs. These are configured in
6-
<<jvm-options,`jvm.options`>> and output to the same default location as
6+
<<set-jvm-options,`jvm.options`>> and output to the same default location as
77
the {es} logs. The default configuration rotates the logs every 64 MB and
88
can consume up to 2 GB of disk space.
99

docs/reference/setup/important-settings/heap-dump-path.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[[heap-dump-path]]
22
[discrete]
3-
=== JVM heap dump path setting
3+
==== JVM heap dump path setting
44

55
By default, {es} configures the JVM to dump the heap on out of
66
memory exceptions to the default data directory. On <<rpm,RPM>> and
@@ -9,7 +9,7 @@ memory exceptions to the default data directory. On <<rpm,RPM>> and
99
the `data` directory is located under the root of the {es} installation.
1010

1111
If this path is not suitable for receiving heap dumps, modify the
12-
`-XX:HeapDumpPath=...` entry in <<jvm-options,`jvm.options`>>:
12+
`-XX:HeapDumpPath=...` entry in <<set-jvm-options,`jvm.options`>>:
1313

1414
* If you specify a directory, the JVM will generate a filename for the heap
1515
dump based on the PID of the running instance.

0 commit comments

Comments
 (0)