Adds garbage collection flags to improve server performance
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good
This commit is contained in:
parent
c83b5a2edd
commit
c3ea85c20b
@ -370,17 +370,32 @@ public class Server {
|
|||||||
private String getJavaCommand() {
|
private String getJavaCommand() {
|
||||||
ServerLauncherController controller = ServerLauncherController.getInstance();
|
ServerLauncherController controller = ServerLauncherController.getInstance();
|
||||||
|
|
||||||
if (serverVersion.toLowerCase().contains("latest")) {
|
if (versionAtLeast("1.17")) {
|
||||||
return controller.getJavaCommand();
|
return controller.getJavaCommand();
|
||||||
|
} else {
|
||||||
|
return controller.getOldJavaCommand();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the current server version is at least the given version
|
||||||
|
*
|
||||||
|
* @param version <p>The version to require</p>
|
||||||
|
* @return <p>True if the server version is at least the given version</p>
|
||||||
|
*/
|
||||||
|
private boolean versionAtLeast(String version) {
|
||||||
|
if (serverVersion.toLowerCase().contains("latest")) {
|
||||||
|
return true;
|
||||||
} else if (serverVersion.contains(".") && serverVersion.split("\\.").length >= 2) {
|
} else if (serverVersion.contains(".") && serverVersion.split("\\.").length >= 2) {
|
||||||
try {
|
try {
|
||||||
if (Integer.parseInt(serverVersion.split("\\.")[1]) >= 17) {
|
return Integer.parseInt(serverVersion.split("\\.")[0]) >=
|
||||||
return controller.getJavaCommand();
|
Integer.parseInt(version.split("\\.")[0]) &&
|
||||||
}
|
Integer.parseInt(serverVersion.split("\\.")[1]) >=
|
||||||
|
Integer.parseInt(version.split("\\.")[1]);
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return controller.getOldJavaCommand();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -389,17 +404,7 @@ public class Server {
|
|||||||
* @throws IOException <p>If the process cannot be started</p>
|
* @throws IOException <p>If the process cannot be started</p>
|
||||||
*/
|
*/
|
||||||
private void startServerProcess() throws IOException {
|
private void startServerProcess() throws IOException {
|
||||||
ProcessBuilder builder;
|
ProcessBuilder builder = new ProcessBuilder(generateServerProcessArguments());
|
||||||
String serverPath;
|
|
||||||
//Decide the path of the .jar file to be executed
|
|
||||||
if (type.getName().equals("Custom")) {
|
|
||||||
serverPath = this.path + File.separator + serverVersion;
|
|
||||||
} else {
|
|
||||||
serverPath = jarDirectory + this.type.getName() + serverVersion + ".jar";
|
|
||||||
}
|
|
||||||
builder = new ProcessBuilder(getJavaCommand(), "-Xmx" + this.maxRam, "-Xms512M",
|
|
||||||
"-Djline.terminal=jline.UnsupportedTerminal", "-Dcom.mojang.eula.agree=true", "-jar", serverPath,
|
|
||||||
"nogui");
|
|
||||||
builder.directory(new File(this.path));
|
builder.directory(new File(this.path));
|
||||||
builder.redirectErrorStream(true);
|
builder.redirectErrorStream(true);
|
||||||
this.process = builder.start();
|
this.process = builder.start();
|
||||||
@ -417,6 +422,64 @@ public class Server {
|
|||||||
}, 10, 500, TimeUnit.MILLISECONDS);
|
}, 10, 500, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates the process arguments required for starting this Minecraft server
|
||||||
|
*
|
||||||
|
* @return <p>The process arguments required for starting this Minecraft server</p>
|
||||||
|
*/
|
||||||
|
private List<String> generateServerProcessArguments() {
|
||||||
|
//Decide the path of the .jar file to be executed
|
||||||
|
String serverPath;
|
||||||
|
if (type.getName().equalsIgnoreCase("Custom")) {
|
||||||
|
serverPath = this.path + File.separator + serverVersion;
|
||||||
|
} else {
|
||||||
|
serverPath = jarDirectory + this.type.getName() + serverVersion + ".jar";
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> processArguments = new ArrayList<>(20);
|
||||||
|
processArguments.add(getJavaCommand());
|
||||||
|
processArguments.add("-Xmx" + this.maxRam);
|
||||||
|
processArguments.add("-Xms512M");
|
||||||
|
if (versionAtLeast("1.8")) {
|
||||||
|
addGarbageCollectorFlags(processArguments);
|
||||||
|
}
|
||||||
|
processArguments.add("-Djline.terminal=jline.UnsupportedTerminal");
|
||||||
|
processArguments.add("-Dcom.mojang.eula.agree=true");
|
||||||
|
processArguments.add("-jar");
|
||||||
|
processArguments.add(serverPath);
|
||||||
|
processArguments.add("nogui");
|
||||||
|
return processArguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds garbage collector flags to the server process arguments to improve performance
|
||||||
|
*
|
||||||
|
* @param processArguments <p>The process arguments to add the flags to</p>
|
||||||
|
*/
|
||||||
|
private void addGarbageCollectorFlags(List<String> processArguments) {
|
||||||
|
processArguments.add("-XX:+UseG1GC");
|
||||||
|
processArguments.add("-XX:+ParallelRefProcEnabled");
|
||||||
|
processArguments.add("-XX:MaxGCPauseMillis=200");
|
||||||
|
processArguments.add("-XX:+UnlockExperimentalVMOptions");
|
||||||
|
processArguments.add("-XX:+DisableExplicitGC");
|
||||||
|
processArguments.add("-XX:+AlwaysPreTouch");
|
||||||
|
boolean excessiveRam = Integer.parseInt(this.maxRam.substring(0, this.maxRam.length() - 1)) > 11;
|
||||||
|
processArguments.add("-XX:G1NewSizePercent=" + (excessiveRam ? 40 : 30));
|
||||||
|
processArguments.add("-XX:G1MaxNewSizePercent=" + (excessiveRam ? 50 : 40));
|
||||||
|
processArguments.add("-XX:G1HeapRegionSize=" + (excessiveRam ? "16M" : "8M"));
|
||||||
|
processArguments.add("-XX:G1ReservePercent=" + (excessiveRam ? 15 : 20));
|
||||||
|
processArguments.add("-XX:G1HeapWastePercent=5");
|
||||||
|
processArguments.add("-XX:G1MixedGCCountTarget=4");
|
||||||
|
processArguments.add("-XX:InitiatingHeapOccupancyPercent=" + (excessiveRam ? 20 : 15));
|
||||||
|
processArguments.add("-XX:G1MixedGCLiveThresholdPercent=90");
|
||||||
|
processArguments.add("-XX:G1RSetUpdatingPauseTimePercent=5");
|
||||||
|
processArguments.add("-XX:SurvivorRatio=32");
|
||||||
|
processArguments.add("-XX:+PerfDisableSharedMem");
|
||||||
|
processArguments.add("-XX:MaxTenuringThreshold=1");
|
||||||
|
processArguments.add("-Dusing.aikars.flags=https://mcflags.emc.gs");
|
||||||
|
processArguments.add("-Daikars.new.flags=true");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a single console with process output
|
* Updates a single console with process output
|
||||||
*
|
*
|
||||||
@ -580,4 +643,5 @@ public class Server {
|
|||||||
this.getMaxRam()
|
this.getMaxRam()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user