Skip to content

Commit 3c10d5b

Browse files
authored
fix: the launchers memory should not effect the node memory (#1221)
### Motivation The way our launcher works is that all jvm options of the launcher get passed down to the started node instance. Therefore increasing the memory in one of the start files would result in the memory increasing for two different processes. 1. The launcher process it self start is started by the start file 2. The memory of the new node process started by the launcher So that means that the memory consumption is doubled. ### Modification Made sure to remove the -xmx and -xms options of the launcher before passing the remaining options to the node and introduced a new option in the launcher.cnl. The new option `cloudnet.node.memory` is the new way to set the memory of the node (in megabytes). ### Result The memory is not occupied twice and the node memory is not dependant on the launcher.
1 parent b1b88bc commit 3c10d5b

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

.template/start.bat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ IF %ERRORLEVEL% NEQ 0 (
66
ECHO No valid java installation was found, please install java in order to run CloudNet
77
EXIT /b 1
88
) ELSE (
9-
java -Xms256M -Xmx256M -XX:+UseZGC -XX:+PerfDisableSharedMem -XX:+DisableExplicitGC -jar launcher.jar
9+
:: DO NOT CHANGE THE SUPPLIED MEMORY HERE. THIS HAS NO EFFECT ON THE NODE INSTANCE. USE THE launcher.cnl INSTEAD
10+
java -Xms128M -Xmx128M -XX:+UseZGC -XX:+PerfDisableSharedMem -XX:+DisableExplicitGC -jar launcher.jar
1011
)

.template/start.command

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ cd "$(dirname "$0")" || exit 1
33

44
# check if java is installed
55
if [ -x "$(command -v java)" ]; then
6-
java -Xms256M -Xmx256M -XX:+UseZGC -XX:+PerfDisableSharedMem -XX:+DisableExplicitGC -jar launcher.jar
6+
# DO NOT CHANGE THE SUPPLIED MEMORY HERE. THIS HAS NO EFFECT ON THE NODE INSTANCE. USE THE launcher.cnl INSTEAD
7+
java -Xms128M -Xmx128M -XX:+UseZGC -XX:+PerfDisableSharedMem -XX:+DisableExplicitGC -jar launcher.jar
78
else
89
echo "No valid java installation was found, please install java in order to run CloudNet"
910
exit 1

.template/start.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ if [ -x "$(command -v java)" ]; then
66
# if screen is present use that
77
# this check is elevated as tmux is sometimes present by default
88
if [ -x "$(command -v screen)" ]; then
9-
screen -DRSq CloudNet java -Xms256M -Xmx256M -XX:+UseZGC -XX:+PerfDisableSharedMem -XX:+DisableExplicitGC -jar launcher.jar
9+
# DO NOT CHANGE THE SUPPLIED MEMORY HERE. THIS HAS NO EFFECT ON THE NODE INSTANCE. USE THE launcher.cnl INSTEAD
10+
screen -DRSq CloudNet java -Xms128M -Xmx128M -XX:+UseZGC -XX:+PerfDisableSharedMem -XX:+DisableExplicitGC -jar launcher.jar
1011
elif [ -x "$(command -v tmux)" ]; then
11-
tmux new-session -As CloudNet java -Xms256M -Xmx256M -XX:+UseZGC -XX:+PerfDisableSharedMem -XX:+DisableExplicitGC -jar launcher.jar
12+
# DO NOT CHANGE THE SUPPLIED MEMORY HERE. THIS HAS NO EFFECT ON THE NODE INSTANCE. USE THE launcher.cnl INSTEAD
13+
tmux new-session -As CloudNet java -Xms128M -Xmx128M -XX:+UseZGC -XX:+PerfDisableSharedMem -XX:+DisableExplicitGC -jar launcher.jar
1214
else
1315
echo "No screen or tmux installation found, you need to install at least one of them to run CloudNet"
1416
exit 1

launcher/java17/src/main/java/eu/cloudnetservice/launcher/java17/ApplicationBootstrap.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Arrays;
2525
import java.util.LinkedHashSet;
2626
import java.util.List;
27+
import java.util.Locale;
2728
import java.util.Set;
2829
import java.util.concurrent.ExecutionException;
2930
import java.util.concurrent.TimeUnit;
@@ -51,7 +52,8 @@ public static void bootstrap(
5152
@NonNull Path applicationPath,
5253
@NonNull Set<Path> dependencies,
5354
@NonNull String[] processArguments,
54-
int debuggerPort
55+
int debuggerPort,
56+
int nodeProcessMemory
5557
) throws Exception {
5658
// resolve the current jar, we only append the launcher jar to it in case someone needs access to it
5759
var currentJar = Path.of(ApplicationBootstrap.class
@@ -66,8 +68,18 @@ public static void bootstrap(
6668
Set<String> arguments = new LinkedHashSet<>();
6769
arguments.add(resolveJavaExecutable());
6870

71+
// remove the xms and xmx options as we want to set them later on
72+
var filteredInputArguments = RUNTIME_MX_BEAN.getInputArguments().stream().filter(inputArgument -> {
73+
var lowerCaseInput = inputArgument.toLowerCase(Locale.ROOT);
74+
return !lowerCaseInput.startsWith("-xmx") && !lowerCaseInput.startsWith("-xms");
75+
}).toList();
76+
6977
// add the arguments supplied to the current process
70-
arguments.addAll(RUNTIME_MX_BEAN.getInputArguments());
78+
arguments.addAll(filteredInputArguments);
79+
80+
// add the memory options for the node now
81+
arguments.add("-Xmx" + nodeProcessMemory + 'M');
82+
arguments.add("-Xms" + nodeProcessMemory + 'M');
7183

7284
// add our default arguments & all system properties we might have set
7385
arguments.addAll(DEFAULT_PROCESS_ARGUMENTS);

launcher/java17/src/main/java/eu/cloudnetservice/launcher/java17/CloudNetLauncher.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,12 @@ private void startApplication() throws Exception {
148148
// resolve the debugger port; use -1 if not given to disable the debugger
149149
int debugPort = CommandLineHelper.findProperty(this.commandLineArguments, "debug.port", "-1", Integer::parseInt);
150150

151+
// resolve the memory for the node process
152+
int nodeMemory = CommandLineHelper.findProperty(this.commandLineArguments, "node.memory", "256", Integer::parseInt);
153+
151154
// resolve all dependencies & start the application
152155
var dependencies = DependencyHelper.loadFromLibrariesFile(cloudNetJarPath);
153-
ApplicationBootstrap.bootstrap(cloudNetJarPath, dependencies, this.originalArgs, debugPort);
156+
ApplicationBootstrap.bootstrap(cloudNetJarPath, dependencies, this.originalArgs, debugPort, nodeMemory);
154157
}
155158

156159
private void runCnlInterpreter() throws Exception {

launcher/java17/src/main/resources/launcher.cnl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ var cloudnet.updateBranch beta
4646
# each level includes all messages for levels lower than itself (in the above list: left to right) too
4747
var cloudnet.logging.defaultlevel INFO
4848

49+
# This value sets the memory settings of the JVM for the cloudnet node.
50+
# The value set here is to be specified in megabytes and describes -xmx as well as -xms.
51+
#
52+
# A change in the associated start files (e.g. start.sh) has no effect on the node and should therefore not be changed.
53+
var cloudnet.node.memory 256
54+
4955
#
5056
# CloudNet runtime properties
5157
#

0 commit comments

Comments
 (0)