Files
KeYiMC/patches/server/0026-Remove-background-executor.patch
2022-12-02 12:03:46 +08:00

81 lines
4.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MartijnMuijsers <martijnmuijsers@live.nl>
Date: Tue, 29 Nov 2022 14:21:44 +0100
Subject: [PATCH] Remove background executor
License: AGPL-3.0 (https://www.gnu.org/licenses/agpl-3.0.html)
This patch was taken from Gale.
diff --git a/src/main/java/net/minecraft/Util.java b/src/main/java/net/minecraft/Util.java
index 6b7943e8348b0a41ca69fb56ccfd5f1c1484eb07..e14245a77b40fca4bacf82295ad390339aba08a9 100644
--- a/src/main/java/net/minecraft/Util.java
+++ b/src/main/java/net/minecraft/Util.java
@@ -72,6 +72,7 @@ import net.minecraft.util.RandomSource;
import net.minecraft.util.TimeSource;
import net.minecraft.util.datafix.DataFixers;
import net.minecraft.world.level.block.state.properties.Property;
+import org.galemc.gale.concurrent.AsyncExecutor;
import org.slf4j.Logger;
public class Util {
@@ -80,7 +81,7 @@ public class Util {
private static final String MAX_THREADS_SYSTEM_PROPERTY = "max.bg.threads";
private static final AtomicInteger WORKER_COUNT = new AtomicInteger(1);
private static final ExecutorService BOOTSTRAP_EXECUTOR = makeExecutor("Bootstrap", -2); // Paper - add -2 priority
- private static final ExecutorService BACKGROUND_EXECUTOR = makeExecutor("Main", -1); // Paper - add -1 priority
+ private static final ExecutorService BACKGROUND_EXECUTOR = AsyncExecutor.instance; // Gale - centralized async execution - remove background executor
// Paper start - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
public static final ExecutorService PROFILE_EXECUTOR = Executors.newFixedThreadPool(2, new java.util.concurrent.ThreadFactory() {
@@ -219,7 +220,6 @@ public class Util {
}
public static void shutdownExecutors() {
- shutdownExecutor(BACKGROUND_EXECUTOR);
shutdownExecutor(IO_POOL);
}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 462689f5c35c5379a0281fe61ad91ae3288d279d..b77b1bc9a5ce1373ff5c5aacc3f4c68c1c735849 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -994,11 +994,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
MinecraftServer.LOGGER.error("Failed to unlock level {}", this.storageSource.getLevelId(), ioexception1);
}
// Spigot start
- // Gale start - centralized async execution - remove Paper async executor
- AsyncExecutor.instance.shutdown(); // Paper
- try { AsyncExecutor.instance.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS); // Paper
- // Gale end - centralized async execution - remove Paper async executor
- } catch (java.lang.InterruptedException ignored) {} // Paper
if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) {
MinecraftServer.LOGGER.info("Saving usercache.json");
this.getProfileCache().save(false); // Paper
@@ -1008,6 +1003,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
LOGGER.info("Flushing Chunk IO");
io.papermc.paper.chunk.system.io.RegionFileIOThread.close(true); // Paper // Paper - rewrite chunk system
LOGGER.info("Closing Thread Pool");
+ // Gale start - centralized async execution - remove Paper async executor, remove background executor
+ AsyncExecutor.instance.shutdown(); // Paper
+ try {
+ AsyncExecutor.instance.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS); // Paper
+ // Gale end - centralized async execution - remove Paper async executor
+ } catch (java.lang.InterruptedException ignored) {} // Paper
+ // Gale start - centralized async execution - remove background executor
Util.shutdownExecutors(); // Paper
LOGGER.info("Closing Server");
try {
diff --git a/src/main/java/org/galemc/gale/concurrent/AsyncExecutor.java b/src/main/java/org/galemc/gale/concurrent/AsyncExecutor.java
index de182b9473963b95085fa612f70884a56765ae43..fff4549d86e672dc7b9959ac5dd51fd04d4d62c3 100644
--- a/src/main/java/org/galemc/gale/concurrent/AsyncExecutor.java
+++ b/src/main/java/org/galemc/gale/concurrent/AsyncExecutor.java
@@ -34,6 +34,7 @@ public final class AsyncExecutor extends ThreadPoolExecutor {
public static final int parallelism;
static {
int parallelismByEnvironmentVariable = Integer.getInteger("gale.threads.async", -1);
+ parallelismByEnvironmentVariable = Math.max(parallelismByEnvironmentVariable, Integer.getInteger("Paper.WorkerThreadCount", -1)); // Gale - centralized async execution - remove background executor
parallelism = Math.max(1, parallelismByEnvironmentVariable > 0 ? parallelismByEnvironmentVariable : CPUCoresEstimation.get() - 2);
}