Skip to content

Commit

Permalink
Offload more threads to virtual threads
Browse files Browse the repository at this point in the history
  • Loading branch information
404Setup committed Sep 2, 2024
1 parent 7c00eb1 commit e480506
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 11 deletions.
5 changes: 3 additions & 2 deletions patches/server/0002-Add-some-required-dependencies.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Add some required dependencies


diff --git a/build.gradle.kts b/build.gradle.kts
index 124dd83b65ed62c851981065745d8762e952beee..24953fb68973b109362979a7cc7b77195aa7a1d2 100644
index 124dd83b65ed62c851981065745d8762e952beee..7f0ec9be763f48067fb967d6bcbb0448a22bb256 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -85,6 +85,26 @@ dependencies {
@@ -85,6 +85,27 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
// Vine end

Expand All @@ -18,6 +18,7 @@ index 124dd83b65ed62c851981065745d8762e952beee..24953fb68973b109362979a7cc7b7719
+ implementation("org.lz4:lz4-java:1.8.0")
+
+ implementation("org.reflections:reflections:0.10.2")
+ implementation("org.simdjson:simdjson-java:0.3.0")
+
+ val brotli4jVersion = "1.16.0"
+ implementation ( group = "com.aayushatharva.brotli4j", name = "brotli4j", version = brotli4jVersion )
Expand Down
14 changes: 7 additions & 7 deletions patches/server/0004-Vine-Config.patch
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ index 0000000000000000000000000000000000000000..3f89f14785f4ee57c1c76e8c37fbe016
\ No newline at end of file
diff --git a/src/main/kotlin/one/tranic/vine/config/module/feature/Value.kt b/src/main/kotlin/one/tranic/vine/config/module/feature/Value.kt
new file mode 100644
index 0000000000000000000000000000000000000000..a881b97d383c640a81332910298ab2845fdece27
index 0000000000000000000000000000000000000000..69841c822202f8b9968fd256130c7904938267ca
--- /dev/null
+++ b/src/main/kotlin/one/tranic/vine/config/module/feature/Value.kt
@@ -0,0 +1,87 @@
Expand Down Expand Up @@ -628,7 +628,7 @@ index 0000000000000000000000000000000000000000..a881b97d383c640a81332910298ab284
+ if (Locker.secureSeed == null) {
+ Feature.secureSeed = it
+ Locker.secureSeed = it
+ if (it) VineLogger.warn("SecureSeed has been enabled, and this value cannot be modified before deleting the map.")
+ if (it) VineLogger.warn("** SecureSeed has been enabled, and this value cannot be modified before deleting the map.")
+ } else if (Locker.secureSeed != it) {
+ VineLogger.error("Forbidden to modify the parameter \"feature.secure-seed\" during runtime!!!")
+ }
Expand All @@ -638,11 +638,11 @@ index 0000000000000000000000000000000000000000..a881b97d383c640a81332910298ab284
+ if (it) {
+ VineLogger.warn(
+ listOf(
+ "Virtual threads are enabled.",
+ "Vine will try to replace all explicit platform threads with virtual threads,",
+ "which may have some undesirable consequences. Do not use it in production if",
+ "you are not sure it will be stable.",
+ "The ShreddedPaper thread will continue to use the platform thread."
+ "********",
+ "Virtual threads enabled.",
+ "Will try to offload threads other than ShreddedPaper and ChunkThread to dummy threads",
+ "This feature is very experimental and may have some undesirable consequences",
+ "********"
+ )
+ )
+ }
Expand Down
149 changes: 149 additions & 0 deletions patches/server/0012-Try-Virtual-threads.patch
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,155 @@ index 52c62442e68634358ea4112fa1aacdab2cca97bb..9231375976f0cd21c5e8a808736cb0db

public final ChatDecorator improvedChatDecorator = new io.papermc.paper.adventure.ImprovedChatDecorator(this); // Paper - adventure
public ChatDecorator getChatDecorator() {
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index 7105802aee38f8f0b896e97e59c566dbee8964d2..26450404dc8f1c06a19a925cedb3d53e435917d7 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -95,60 +95,60 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface

@Override
public boolean initServer() throws IOException {
- Thread thread = new Thread("Server console handler") {
- public void run() {
- // CraftBukkit start
- if (!org.bukkit.craftbukkit.Main.useConsole) {
- return;
- }
- // Paper start - Use TerminalConsoleAppender
- if (DedicatedServer.this.gui == null || System.console() != null) // Purpur - has no GUI or has console (did not double-click)
- new com.destroystokyo.paper.console.PaperConsole(DedicatedServer.this).start();
- /*
- jline.console.ConsoleReader bufferedreader = DedicatedServer.this.reader;
+ Runnable run = () -> {
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.Main.useConsole) {
+ return;
+ }
+ // Paper start - Use TerminalConsoleAppender
+ if (DedicatedServer.this.gui == null || System.console() != null) // Purpur - has no GUI or has console (did not double-click)
+ new com.destroystokyo.paper.console.PaperConsole(DedicatedServer.this).start();
+ /*
+ jline.console.ConsoleReader bufferedreader = DedicatedServer.this.reader;

- // MC-33041, SPIGOT-5538: if System.in is not valid due to javaw, then return
- try {
- System.in.available();
- } catch (IOException ex) {
- return;
- }
- // CraftBukkit end
+ // MC-33041, SPIGOT-5538: if System.in is not valid due to javaw, then return
+ try {
+ System.in.available();
+ } catch (IOException ex) {
+ return;
+ }
+ // CraftBukkit end

- String s;
+ String s;

- try {
- // CraftBukkit start - JLine disabling compatibility
- while (!DedicatedServer.this.isStopped() && DedicatedServer.this.isRunning()) {
- if (org.bukkit.craftbukkit.Main.useJline) {
- s = bufferedreader.readLine(">", null);
- } else {
- s = bufferedreader.readLine();
- }
+ try {
+ // CraftBukkit start - JLine disabling compatibility
+ while (!DedicatedServer.this.isStopped() && DedicatedServer.this.isRunning()) {
+ if (org.bukkit.craftbukkit.Main.useJline) {
+ s = bufferedreader.readLine(">", null);
+ } else {
+ s = bufferedreader.readLine();
+ }

- // SPIGOT-5220: Throttle if EOF (ctrl^d) or stdin is /dev/null
- if (s == null) {
- try {
- Thread.sleep(50L);
- } catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- continue;
+ // SPIGOT-5220: Throttle if EOF (ctrl^d) or stdin is /dev/null
+ if (s == null) {
+ try {
+ Thread.sleep(50L);
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
}
- if (s.trim().length() > 0) { // Trim to filter lines which are just spaces
- DedicatedServer.this.issueCommand(s, DedicatedServer.this.getServerCommandListener());
- }
- // CraftBukkit end
+ continue;
+ }
+ if (s.trim().length() > 0) { // Trim to filter lines which are just spaces
+ DedicatedServer.this.issueCommand(s, DedicatedServer.this.getServerCommandListener());
}
- } catch (IOException ioexception) {
- DedicatedServer.LOGGER.error("Exception handling console input", ioexception);
+ // CraftBukkit end
}
-
- */
- // Paper end
+ } catch (IOException ioexception) {
+ DedicatedServer.LOGGER.error("Exception handling console input", ioexception);
}
+
+ */
+ // Paper end
};

+ Thread thread = one.tranic.vine.util.AnyThread.getThread(run, "Server console handler");
+
// CraftBukkit start - TODO: handle command-line logging arguments
java.util.logging.Logger global = java.util.logging.Logger.getLogger("");
global.setUseParentHandlers(false);
@@ -372,7 +372,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
}

if (false && this.getMaxTickLength() > 0L) { // Spigot - disable
- Thread thread1 = new Thread(new ServerWatchdog(this));
+ Thread thread1 = one.tranic.vine.util.AnyThread.getThread(new ServerWatchdog(this));

thread1.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandlerWithName(DedicatedServer.LOGGER));
thread1.setName("Server Watchdog");
@@ -530,7 +530,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
sender.sendMessage(net.kyori.adventure.text.Component.text("Failed to dump chunk information, see console", net.kyori.adventure.text.format.NamedTextColor.RED));
}
};
- Thread t = new Thread(run);
+ Thread t = one.tranic.vine.util.AnyThread.getThread(run);
t.setName("Async debug thread #" + ASYNC_DEBUG_CHUNKS_COUNT.getAndIncrement());
t.setDaemon(true);
t.start();
diff --git a/src/main/java/net/minecraft/server/gui/MinecraftServerGui.java b/src/main/java/net/minecraft/server/gui/MinecraftServerGui.java
index 9aaa8989832c238c66eb8c21256309cc37c2f18d..27d692e370e02ba4e7ba6262195ba01988918673 100644
--- a/src/main/java/net/minecraft/server/gui/MinecraftServerGui.java
+++ b/src/main/java/net/minecraft/server/gui/MinecraftServerGui.java
@@ -219,14 +219,15 @@ public class MinecraftServerGui extends JComponent {
jpanel.add(jscrollpane, "Center");
jpanel.add(jtextfield, "South");
jpanel.setBorder(new TitledBorder(new EtchedBorder(), "Log and chat"));
- this.logAppenderThread = new Thread(() -> {
+ Runnable run = () -> {
String s;

while ((s = LogQueues.getNextLogEvent("ServerGuiConsole")) != null) {
this.print(jtextarea, jscrollpane, s);
}

- });
+ };
+ this.logAppenderThread = one.tranic.vine.util.AnyThread.getThread(run);
this.logAppenderThread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(MinecraftServerGui.LOGGER));
this.logAppenderThread.setDaemon(true);
return jpanel;
diff --git a/src/main/java/net/minecraft/util/thread/NamedThreadFactory.java b/src/main/java/net/minecraft/util/thread/NamedThreadFactory.java
index 04460b81d6351f63103199a980e463070c233300..01d3ab53bdf12146b372dea464a4298325b682ed 100644
--- a/src/main/java/net/minecraft/util/thread/NamedThreadFactory.java
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0032-Leaf-Cache-player-profileResult.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Leaf: Cache player profileResult


diff --git a/build.gradle.kts b/build.gradle.kts
index 24953fb68973b109362979a7cc7b77195aa7a1d2..44d6acfb60bfdfd2001d20d846b134e14edb0029 100644
index 7f0ec9be763f48067fb967d6bcbb0448a22bb256..505076251981597e8830f9c978869a930cbbece0 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -105,6 +105,7 @@ dependencies {
@@ -106,6 +106,7 @@ dependencies {
runtimeOnly ( group = "com.aayushatharva.brotli4j", name = "native-osx-x86_64", version = brotli4jVersion )
runtimeOnly ( group = "com.aayushatharva.brotli4j", name = "native-osx-aarch64", version = brotli4jVersion )
// Vine end
Expand Down

0 comments on commit e480506

Please sign in to comment.