Skip to content

Commit 2c18cbf

Browse files
authored
Introduce system JVM options (#48252)
This commit moves JVM options that we are setting on behalf of the user that we do not expect them to fiddle with out of the jvm.options configuration file and into the JVM options parser. In this way, we discourage fiddling with these settings, but more importantly, we ensure that as we evolve or add to these settings that a user would pick these pick instead of being left behind if they have a modified jvm.options file and do not pick any new that come with the distribution.
1 parent 497f644 commit 2c18cbf

File tree

3 files changed

+77
-47
lines changed

3 files changed

+77
-47
lines changed

distribution/src/config/jvm.options

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -44,47 +44,7 @@
4444
# -XX:G1ReservePercent=25
4545
# -XX:InitiatingHeapOccupancyPercent=30
4646

47-
## DNS cache policy
48-
# cache ttl in seconds for positive DNS lookups noting that this overrides the
49-
# JDK security property networkaddress.cache.ttl; set to -1 to cache forever
50-
-Des.networkaddress.cache.ttl=60
51-
# cache ttl in seconds for negative DNS lookups noting that this overrides the
52-
# JDK security property networkaddress.cache.negative ttl; set to -1 to cache
53-
# forever
54-
-Des.networkaddress.cache.negative.ttl=10
55-
56-
## optimizations
57-
58-
# pre-touch memory pages used by the JVM during initialization
59-
-XX:+AlwaysPreTouch
60-
61-
## basic
62-
63-
# explicitly set the stack size
64-
-Xss1m
65-
66-
# set to headless, just in case
67-
-Djava.awt.headless=true
68-
69-
# ensure UTF-8 encoding by default (e.g. filenames)
70-
-Dfile.encoding=UTF-8
71-
72-
# use our provided JNA always versus the system one
73-
-Djna.nosys=true
74-
75-
# turn off a JDK optimization that throws away stack traces for common
76-
# exceptions because stack traces are important for debugging
77-
-XX:-OmitStackTraceInFastThrow
78-
79-
# flags to configure Netty
80-
-Dio.netty.noUnsafe=true
81-
-Dio.netty.noKeySetOptimization=true
82-
-Dio.netty.recycler.maxCapacityPerThread=0
83-
84-
# log4j 2
85-
-Dlog4j.shutdownHookEnabled=false
86-
-Dlog4j2.disable.jmx=true
87-
47+
## JVM temporary directory
8848
-Djava.io.tmpdir=${ES_TMPDIR}
8949

9050
## heap dumps
@@ -100,8 +60,5 @@ ${heap.dump.path}
10060
# specify an alternative path for JVM fatal error logs
10161
${error.file}
10262

103-
# GC logging
63+
## GC logging
10464
-Xlog:gc*,gc+age=trace,safepoint:file=${loggc}:utctime,pid,tags:filecount=32,filesize=64m
105-
# due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise
106-
# time/date parsing will break in an incompatible way for some date patterns and locals
107-
-Djava.locale.providers=SPI,COMPAT

distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmOptionsParser.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,13 @@ public void accept(final int lineNumber, final String line) {
9090
final List<String> substitutedJvmOptions =
9191
substitutePlaceholders(jvmOptions, Map.of("ES_TMPDIR", System.getenv("ES_TMPDIR")));
9292
final List<String> ergonomicJvmOptions = JvmErgonomics.choose(substitutedJvmOptions);
93-
substitutedJvmOptions.addAll(ergonomicJvmOptions);
94-
final String spaceDelimitedJvmOptions = spaceDelimitJvmOptions(substitutedJvmOptions);
93+
final List<String> systemJvmOptions = SystemJvmOptions.systemJvmOptions();
94+
final List<String> finalJvmOptions =
95+
new ArrayList<>(systemJvmOptions.size() + substitutedJvmOptions.size() + ergonomicJvmOptions.size());
96+
finalJvmOptions.addAll(systemJvmOptions); // add the system JVM options first so that they can be overridden
97+
finalJvmOptions.addAll(substitutedJvmOptions);
98+
finalJvmOptions.addAll(ergonomicJvmOptions);
99+
final String spaceDelimitedJvmOptions = spaceDelimitJvmOptions(finalJvmOptions);
95100
Launchers.outPrintln(spaceDelimitedJvmOptions);
96101
Launchers.exit(0);
97102
} else {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.tools.launchers;
21+
22+
import java.util.List;
23+
24+
final class SystemJvmOptions {
25+
26+
static List<String> systemJvmOptions() {
27+
return List.of(
28+
/*
29+
* Cache ttl in seconds for positive DNS lookups noting that this overrides the JDK security property networkaddress.cache.ttl;
30+
* can be set to -1 to cache forever.
31+
*/
32+
"-Des.networkaddress.cache.ttl=60",
33+
/*
34+
* Cache ttl in seconds for negative DNS lookups noting that this overrides the JDK security property
35+
* networkaddress.cache.negative ttl; set to -1 to cache forever.
36+
*/
37+
"-Des.networkaddress.cache.negative.ttl=10",
38+
// pre-touch JVM emory pages during initialization
39+
"-XX:+AlwaysPreTouch",
40+
// explicitly set the stack size
41+
"-Xss1m",
42+
// set to headless, just in case,
43+
"-Djava.awt.headless=true",
44+
// ensure UTF-8 encoding by default (e.g., filenames)
45+
"-Dfile.encoding=UTF-8",
46+
// use our provided JNA always versus the system one
47+
"-Djna.nosys=true",
48+
/*
49+
* Turn off a JDK optimization that throws away stack traces for common exceptions because stack traces are important for
50+
* debugging.
51+
*/
52+
"-XX:-OmitStackTraceInFastThrow",
53+
// flags to configure Netty
54+
"-Dio.netty.noUnsafe=true",
55+
"-Dio.netty.noKeySetOptimization=true",
56+
"-Dio.netty.recycler.maxCapacityPerThread=0",
57+
"-Dio.netty.allocator.numDirectArenas=0",
58+
// log4j 2
59+
"-Dlog4j.shutdownHookEnabled=false",
60+
"-Dlog4j2.disable.jmx=true",
61+
/*
62+
* Due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise time/date
63+
* parsing will break in an incompatible way for some date patterns and locales.
64+
*/
65+
"-Djava.locale.providers=SPI,COMPAT");
66+
}
67+
68+
}

0 commit comments

Comments
 (0)