Skip to content

Commit 3334c4c

Browse files
committed
Introduce system JVM options (elastic#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 726c67d commit 3334c4c

File tree

3 files changed

+78
-47
lines changed

3 files changed

+78
-47
lines changed

distribution/src/config/jvm.options

+1-45
Original file line numberDiff line numberDiff line change
@@ -46,47 +46,7 @@
4646
# 10-:-XX:G1ReservePercent=25
4747
# 10-:-XX:InitiatingHeapOccupancyPercent=30
4848

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

9252
## heap dumps
@@ -103,7 +63,6 @@ ${heap.dump.path}
10363
${error.file}
10464

10565
## JDK 8 GC logging
106-
10766
8:-XX:+PrintGCDetails
10867
8:-XX:+PrintGCDateStamps
10968
8:-XX:+PrintTenuringDistribution
@@ -115,6 +74,3 @@ ${error.file}
11574

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

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

+7-2
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, Collections.singletonMap("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 {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.Arrays;
23+
import java.util.Collections;
24+
import java.util.List;
25+
26+
final class SystemJvmOptions {
27+
28+
static List<String> systemJvmOptions() {
29+
return Collections.unmodifiableList(Arrays.asList(
30+
/*
31+
* Cache ttl in seconds for positive DNS lookups noting that this overrides the JDK security property networkaddress.cache.ttl;
32+
* can be set to -1 to cache forever.
33+
*/
34+
"-Des.networkaddress.cache.ttl=60",
35+
/*
36+
* Cache ttl in seconds for negative DNS lookups noting that this overrides the JDK security property
37+
* networkaddress.cache.negative ttl; set to -1 to cache forever.
38+
*/
39+
"-Des.networkaddress.cache.negative.ttl=10",
40+
// pre-touch JVM emory pages during initialization
41+
"-XX:+AlwaysPreTouch",
42+
// explicitly set the stack size
43+
"-Xss1m",
44+
// set to headless, just in case,
45+
"-Djava.awt.headless=true",
46+
// ensure UTF-8 encoding by default (e.g., filenames)
47+
"-Dfile.encoding=UTF-8",
48+
// use our provided JNA always versus the system one
49+
"-Djna.nosys=true",
50+
/*
51+
* Turn off a JDK optimization that throws away stack traces for common exceptions because stack traces are important for
52+
* debugging.
53+
*/
54+
"-XX:-OmitStackTraceInFastThrow",
55+
// flags to configure Netty
56+
"-Dio.netty.noUnsafe=true",
57+
"-Dio.netty.noKeySetOptimization=true",
58+
"-Dio.netty.recycler.maxCapacityPerThread=0",
59+
"-Dio.netty.allocator.numDirectArenas=0",
60+
// log4j 2
61+
"-Dlog4j.shutdownHookEnabled=false",
62+
"-Dlog4j2.disable.jmx=true",
63+
/*
64+
* Due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise time/date
65+
* parsing will break in an incompatible way for some date patterns and locales.
66+
*/
67+
"-Djava.locale.providers=SPI,COMPAT"));
68+
}
69+
70+
}

0 commit comments

Comments
 (0)