diff --git a/patches/server/0145-Base-thread-pool.patch b/patches/server/0145-Base-thread-pool.patch index db9b9fd..d7bcf47 100644 --- a/patches/server/0145-Base-thread-pool.patch +++ b/patches/server/0145-Base-thread-pool.patch @@ -1,6 +1,6 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers -Date: Sun, 29 Jan 2023 23:02:18 +0100 +Date: Sun, 29 Jan 2023 23:41:12 +0100 Subject: [PATCH] Base thread pool License: AGPL-3.0 (https://www.gnu.org/licenses/agpl-3.0.html) @@ -442,112 +442,6 @@ index fc57850b80303fcade89ca95794f63910404a407..04c678712f154c2da33e1e38c8583c40 this.id = id; } -diff --git a/src/main/java/io/papermc/paper/world/ThreadedWorldUpgrader.java b/src/main/java/io/papermc/paper/world/ThreadedWorldUpgrader.java -index 95cac7edae8ac64811fc6a2f6b97dd4a0fceb0b0..a376259202b4a16c67db4d3ef071e0b395aca524 100644 ---- a/src/main/java/io/papermc/paper/world/ThreadedWorldUpgrader.java -+++ b/src/main/java/io/papermc/paper/world/ThreadedWorldUpgrader.java -@@ -7,25 +7,21 @@ import net.minecraft.nbt.CompoundTag; - import net.minecraft.resources.ResourceKey; - import net.minecraft.util.worldupdate.WorldUpgrader; - import net.minecraft.world.level.ChunkPos; --import net.minecraft.world.level.Level; - import net.minecraft.world.level.chunk.ChunkGenerator; - import net.minecraft.world.level.chunk.storage.ChunkStorage; - import net.minecraft.world.level.chunk.storage.RegionFileStorage; --import net.minecraft.world.level.dimension.DimensionType; - import net.minecraft.world.level.dimension.LevelStem; --import net.minecraft.world.level.levelgen.WorldGenSettings; - import net.minecraft.world.level.storage.DimensionDataStorage; - import net.minecraft.world.level.storage.LevelStorageSource; - import org.apache.logging.log4j.LogManager; - import org.apache.logging.log4j.Logger; -+import org.galemc.gale.executor.queue.BaseTaskQueues; -+ - import java.io.File; - import java.io.IOException; - import java.text.DecimalFormat; - import java.util.Optional; - import java.util.concurrent.ExecutorService; --import java.util.concurrent.Executors; --import java.util.concurrent.ThreadFactory; --import java.util.concurrent.atomic.AtomicInteger; - import java.util.concurrent.atomic.AtomicLong; - import java.util.function.Supplier; - -@@ -46,6 +42,10 @@ public class ThreadedWorldUpgrader { - this.dimensionType = dimensionType; - this.worldName = worldName; - this.worldDir = worldDir; -+ // Gale start - base thread pool - remove world upgrade executors -+ this.threadPool = BaseTaskQueues.scheduledAsync.yieldingExecutor; -+ /* -+ // Gale end - base thread pool - remove world upgrade executors - this.threadPool = Executors.newFixedThreadPool(Math.max(1, threads), new ThreadFactory() { - private final AtomicInteger threadCounter = new AtomicInteger(); - -@@ -61,6 +61,7 @@ public class ThreadedWorldUpgrader { - return ret; - } - }); -+ */ // Gale - base thread pool - remove world upgrade executors - this.dataFixer = dataFixer; - this.generatorKey = generatorKey; - this.removeCaches = removeCaches; -diff --git a/src/main/java/net/minecraft/Util.java b/src/main/java/net/minecraft/Util.java -index 5ef58831a857fd8aa4ac30147762dc17d773a53e..6b109d92dec227d4a91a455caf596beb112a8351 100644 ---- a/src/main/java/net/minecraft/Util.java -+++ b/src/main/java/net/minecraft/Util.java -@@ -26,9 +26,6 @@ import java.net.URL; - import java.nio.file.Files; - import java.nio.file.Path; - import java.nio.file.spi.FileSystemProvider; --import java.security.AccessController; --import java.security.PrivilegedActionException; --import java.security.PrivilegedExceptionAction; - import java.time.Duration; - import java.time.Instant; - import java.time.ZonedDateTime; -@@ -47,8 +44,6 @@ import java.util.concurrent.ConcurrentHashMap; - import java.util.concurrent.Executor; - import java.util.concurrent.ExecutorService; - import java.util.concurrent.Executors; --import java.util.concurrent.ForkJoinPool; --import java.util.concurrent.ForkJoinWorkerThread; - import java.util.concurrent.LinkedBlockingQueue; - import java.util.concurrent.TimeUnit; - import java.util.concurrent.atomic.AtomicInteger; -@@ -67,11 +62,11 @@ import java.util.stream.Stream; - import javax.annotation.Nullable; - import net.minecraft.resources.ResourceLocation; - import net.minecraft.server.Bootstrap; --import net.minecraft.util.Mth; - 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.executor.queue.BaseTaskQueues; - import org.slf4j.Logger; - - public class Util { -@@ -79,8 +74,8 @@ public class Util { - private static final int DEFAULT_MAX_THREADS = 255; - 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 = BaseTaskQueues.scheduledAsync.yieldingExecutor; // Gale - base thread pool - remove background executor -+ private static final ExecutorService BOOTSTRAP_EXECUTOR = BACKGROUND_EXECUTOR; // Gale - Patina - remove bootstrap 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 +214,6 @@ public class Util { - } - - public static void shutdownExecutors() { -- shutdownExecutor(BACKGROUND_EXECUTOR); - shutdownExecutor(IO_POOL); - } - diff --git a/src/main/java/net/minecraft/commands/arguments/selector/EntitySelector.java b/src/main/java/net/minecraft/commands/arguments/selector/EntitySelector.java index f25b9330e068c7d9e12cb57a7761cfef9ebaf7bc..64d957ba23d306327a26605e1e42f32fa741e2cb 100644 --- a/src/main/java/net/minecraft/commands/arguments/selector/EntitySelector.java @@ -663,7 +557,7 @@ index 0c4c62674b4c7e8e3921c7eb3ef726759ac75075..40f20806cc06106b4aa8e708467dcea9 WorldLoader.InitConfig worldloader_c = Main.loadOrCreateConfig(dedicatedserversettings.getProperties(), convertable_conversionsession, flag, resourcepackrepository); diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index eb951c9fda85d9620d3038a3db22d578db45e878..77b4d5050a5e708522cc07e819db2b3619c46518 100644 +index eb951c9fda85d9620d3038a3db22d578db45e878..ac12cabaf15bc3520ff74d09faa48a135c63f23c 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -40,10 +40,8 @@ import java.util.Optional; @@ -1030,31 +924,7 @@ index eb951c9fda85d9620d3038a3db22d578db45e878..77b4d5050a5e708522cc07e819db2b36 if (worldserver != null) { worldserver.noSave = false; } -@@ -970,9 +1080,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop Util.getMillis() - startTime >= 30 || !BaseTaskQueues.scheduledAsync.hasTasks(), null); // Paper -+ LOGGER.info("Shutting down IO executor..."); -+ // Gale end - base thread pool - remove Paper async executor -+ // Gale end - base thread pool - remove background executor - Util.shutdownExecutors(); // Paper - LOGGER.info("Closing Server"); - try { -@@ -1017,7 +1131,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop optional = Optional.of(this.getFile("server-icon.png")).filter(File::isFile); -@@ -1378,14 +1490,19 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop= 5000000000L) { this.lastServerStatus = i; -@@ -1420,7 +1537,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 0) { this.playerList.saveAll(playerSaveInterval); } @@ -1277,7 +1147,7 @@ index eb951c9fda85d9620d3038a3db22d578db45e878..77b4d5050a5e708522cc07e819db2b36 if (level.paperConfig().chunks.autoSaveInterval.value() > 0) { level.saveIncrementally(fullSave); } -@@ -1432,7 +1549,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 0; // Paper worldserver.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper net.minecraft.world.level.block.entity.HopperBlockEntity.skipHopperEvents = worldserver.paperConfig().hopper.disableMoveEvent || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // Paper -@@ -1569,7 +1684,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels); newLevels.put(level.dimension(), level); this.levels = Collections.unmodifiableMap(newLevels); @@ -1343,7 +1213,7 @@ index eb951c9fda85d9620d3038a3db22d578db45e878..77b4d5050a5e708522cc07e819db2b36 } public void removeLevel(ServerLevel level) { -@@ -1598,6 +1725,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels); newLevels.remove(level.dimension()); this.levels = Collections.unmodifiableMap(newLevels); @@ -1358,7 +1228,7 @@ index eb951c9fda85d9620d3038a3db22d578db45e878..77b4d5050a5e708522cc07e819db2b36 } // CraftBukkit end -@@ -1605,8 +1740,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop CompletableFuture filterTextPacket(T text, BiFunction> filterer) { -@@ -883,21 +884,20 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic - } - - // Paper start -- private static final java.util.concurrent.ExecutorService TAB_COMPLETE_EXECUTOR = java.util.concurrent.Executors.newFixedThreadPool(4, -- new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Tab Complete Thread - #%d").setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build()); -+ private static final java.util.concurrent.ExecutorService TAB_COMPLETE_EXECUTOR = BaseTaskQueues.scheduledAsync.yieldingExecutor; // Gale - base thread pool - remove tab complete executor - // Paper end - @Override - public void handleCustomCommandSuggestions(ServerboundCommandSuggestionPacket packet) { +@@ -891,13 +892,13 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic // PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel()); // Paper - run this async // CraftBukkit start if (this.chatSpamTickCount.addAndGet(io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.tabSpamIncrement) > io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.tabSpamLimit && !this.server.getPlayerList().isOp(this.player.getGameProfile())) { // Paper start - split and make configurable @@ -1593,7 +1454,7 @@ index 14ee62567ace6fc1becf4257761a811d2ab6f71d..93a533bdeb5108f5c3e758f8062de083 return; } // Paper end -@@ -922,7 +922,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic +@@ -922,7 +923,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic if (!event.isHandled()) { if (!event.isCancelled()) { @@ -1602,7 +1463,7 @@ index 14ee62567ace6fc1becf4257761a811d2ab6f71d..93a533bdeb5108f5c3e758f8062de083 ParseResults parseresults = this.server.getCommands().getDispatcher().parse(stringreader, this.player.createCommandSourceStack()); this.server.getCommands().getDispatcher().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> { -@@ -933,7 +933,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic +@@ -933,7 +934,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic this.connection.send(new ClientboundCommandSuggestionsPacket(packet.getId(), suggestEvent.getSuggestions())); // Paper end - Brigadier API }); @@ -1611,7 +1472,7 @@ index 14ee62567ace6fc1becf4257761a811d2ab6f71d..93a533bdeb5108f5c3e758f8062de083 } } else if (!completions.isEmpty()) { final com.mojang.brigadier.suggestion.SuggestionsBuilder builder0 = new com.mojang.brigadier.suggestion.SuggestionsBuilder(command, stringreader.getTotalLength()); -@@ -1247,7 +1247,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic +@@ -1247,7 +1248,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic int byteLength = testString.getBytes(java.nio.charset.StandardCharsets.UTF_8).length; if (byteLength > 256 * 4) { ServerGamePacketListenerImpl.LOGGER.warn(this.player.getScoreboardName() + " tried to send a book with with a page too large!"); @@ -1620,7 +1481,7 @@ index 14ee62567ace6fc1becf4257761a811d2ab6f71d..93a533bdeb5108f5c3e758f8062de083 return; } byteTotal += byteLength; -@@ -1270,14 +1270,14 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic +@@ -1270,14 +1271,14 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic if (byteTotal > byteAllowed) { ServerGamePacketListenerImpl.LOGGER.warn(this.player.getScoreboardName() + " tried to send too large of a book. Book Size: " + byteTotal + " - Allowed: "+ byteAllowed + " - Pages: " + pageList.size()); @@ -1637,7 +1498,7 @@ index 14ee62567ace6fc1becf4257761a811d2ab6f71d..93a533bdeb5108f5c3e758f8062de083 return; } this.lastBookTick = MinecraftServer.currentTick; -@@ -2081,10 +2081,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic +@@ -2081,10 +2082,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic public void handleTeleportToEntityPacket(ServerboundTeleportToEntityPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel()); if (this.player.isSpectator()) { @@ -1649,7 +1510,7 @@ index 14ee62567ace6fc1becf4257761a811d2ab6f71d..93a533bdeb5108f5c3e758f8062de083 Entity entity = packet.getEntity(worldserver); if (entity != null) { -@@ -2233,9 +2230,9 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic +@@ -2233,9 +2231,9 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic } // CraftBukkit end if (ServerGamePacketListenerImpl.isChatMessageIllegal(packet.message())) { @@ -1661,7 +1522,7 @@ index 14ee62567ace6fc1becf4257761a811d2ab6f71d..93a533bdeb5108f5c3e758f8062de083 } else { Optional optional = this.tryHandleChat(packet.message(), packet.timeStamp(), packet.lastSeenMessages()); -@@ -2269,9 +2266,9 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic +@@ -2269,9 +2267,9 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic @Override public void handleChatCommand(ServerboundChatCommandPacket packet) { if (ServerGamePacketListenerImpl.isChatMessageIllegal(packet.command())) { @@ -1673,7 +1534,7 @@ index 14ee62567ace6fc1becf4257761a811d2ab6f71d..93a533bdeb5108f5c3e758f8062de083 } else { Optional optional = this.tryHandleChat(packet.command(), packet.timeStamp(), packet.lastSeenMessages()); -@@ -2353,9 +2350,9 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic +@@ -2353,9 +2351,9 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic private Optional tryHandleChat(String message, Instant timestamp, LastSeenMessages.Update acknowledgment) { if (!this.updateChatOrder(timestamp)) { if (GaleGlobalConfiguration.get().logToConsole.chat.outOfOrderMessageWarning) ServerGamePacketListenerImpl.LOGGER.warn("{} sent out-of-order chat: '{}': {} > {}", this.player.getName().getString(), message, this.lastChatTimeStamp.get().getEpochSecond(), timestamp.getEpochSecond()); // Paper // Gale - do not log out-of-order message warnings @@ -1686,7 +1547,7 @@ index 14ee62567ace6fc1becf4257761a811d2ab6f71d..93a533bdeb5108f5c3e758f8062de083 return Optional.empty(); } else if (this.player.isRemoved() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) { // CraftBukkit - dead men tell no tales this.send(new ClientboundSystemChatPacket(Component.translatable("chat.disabled.options").withStyle(ChatFormatting.RED), false)); -@@ -3290,7 +3287,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic +@@ -3290,7 +3288,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic // Paper start if (!org.bukkit.Bukkit.isPrimaryThread()) { if (recipeSpamPackets.addAndGet(io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.recipeSpamIncrement) > io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.recipeSpamLimit) { @@ -1695,35 +1556,6 @@ index 14ee62567ace6fc1becf4257761a811d2ab6f71d..93a533bdeb5108f5c3e758f8062de083 return; } } -diff --git a/src/main/java/net/minecraft/server/network/TextFilterClient.java b/src/main/java/net/minecraft/server/network/TextFilterClient.java -index 4b3d2280326c7eeda4952c36edff141cbff90e16..e684fa1990d631cafd8e84debe52301fc9ed329f 100644 ---- a/src/main/java/net/minecraft/server/network/TextFilterClient.java -+++ b/src/main/java/net/minecraft/server/network/TextFilterClient.java -@@ -23,7 +23,6 @@ import java.util.List; - import java.util.concurrent.CompletableFuture; - import java.util.concurrent.Executor; - import java.util.concurrent.ExecutorService; --import java.util.concurrent.Executors; - import java.util.concurrent.ThreadFactory; - import java.util.concurrent.atomic.AtomicInteger; - import javax.annotation.Nullable; -@@ -32,6 +31,7 @@ import net.minecraft.Util; - import net.minecraft.network.chat.FilterMask; - import net.minecraft.util.GsonHelper; - import net.minecraft.util.thread.ProcessorMailbox; -+import org.galemc.gale.executor.queue.BaseTaskQueues; - import org.slf4j.Logger; - - public class TextFilterClient implements AutoCloseable { -@@ -62,7 +62,7 @@ public class TextFilterClient implements AutoCloseable { - this.joinEncoder = joinEncoder; - this.leaveEndpoint = leaveEndpoint; - this.leaveEncoder = leaveEncoder; -- this.workerPool = Executors.newFixedThreadPool(parallelism, THREAD_FACTORY); -+ this.workerPool = BaseTaskQueues.scheduledAsync.yieldingExecutor; // Gale - base thread pool - remove text filter executor - } - - private static URL getEndpoint(URI root, @Nullable JsonObject endpoints, String key, String fallback) throws MalformedURLException { diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java index 6f139e6cbb61bfb2be9b8b886bec7cddbb2c8993..0cbef825129b173a5244a195ea68444c216c0b1b 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java diff --git a/patches/server/0146-Run-async-executor-tasks-on-base-thread-pool.patch b/patches/server/0146-Run-async-executor-tasks-on-base-thread-pool.patch index a513fc5..5e29fcc 100644 --- a/patches/server/0146-Run-async-executor-tasks-on-base-thread-pool.patch +++ b/patches/server/0146-Run-async-executor-tasks-on-base-thread-pool.patch @@ -1,6 +1,6 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers -Date: Sun, 29 Jan 2023 23:18:21 +0100 +Date: Sun, 29 Jan 2023 23:52:19 +0100 Subject: [PATCH] Run async executor tasks on base thread pool License: AGPL-3.0 (https://www.gnu.org/licenses/agpl-3.0.html) @@ -26,6 +26,33 @@ index 4b8da38db72d7ebc2d498ec3d711d3b30911096c..80f9e70d5c4330e079feccc9a4b1b595 public static final ThreadPoolExecutor cleanerExecutor = new ThreadPoolExecutor( 1, 1, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), +diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java +index ac12cabaf15bc3520ff74d09faa48a135c63f23c..0019e5eefc4b638526a75dd3706a54033dd9b811 100644 +--- a/src/main/java/net/minecraft/server/MinecraftServer.java ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java +@@ -1080,9 +1080,6 @@ public abstract class MinecraftServer extends MinecraftServerBlockableEventLoop + MinecraftServer.LOGGER.error("Failed to unlock level {}", this.storageSource.getLevelId(), ioexception1); + } + // Spigot start +- io.papermc.paper.util.MCUtil.asyncExecutor.shutdown(); // Paper +- try { io.papermc.paper.util.MCUtil.asyncExecutor.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS); // Paper +- } catch (java.lang.InterruptedException ignored) {} // Paper + if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) { + MinecraftServer.LOGGER.info("Saving usercache.json"); + this.getProfileCache().save(false); // Paper +@@ -1092,6 +1089,12 @@ public abstract class MinecraftServer extends MinecraftServerBlockableEventLoop + 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 - base thread pool - remove Paper async executor ++ long startTime = Util.getMillis(); ++ LOGGER.info("Waiting 30 seconds for asynchronous tasks to finish..."); ++ serverThread.runTasksUntil(() -> Util.getMillis() - startTime >= 30 || !BaseTaskQueues.scheduledAsync.hasTasks(), null); // Paper ++ LOGGER.info("Shutting down IO executor..."); ++ // Gale end - base thread pool - remove Paper async executor + Util.shutdownExecutors(); // Paper + LOGGER.info("Closing Server"); + try { diff --git a/src/main/java/org/galemc/gale/executor/queue/BaseTaskQueueTier.java b/src/main/java/org/galemc/gale/executor/queue/BaseTaskQueueTier.java index f80c0e0ebeee46913ae050db77f888438064d8ae..07212e5d1d9e0e30dc2475fc6e7777aa4d5ce66a 100644 --- a/src/main/java/org/galemc/gale/executor/queue/BaseTaskQueueTier.java diff --git a/patches/server/0147-Run-background-executor-tasks-on-base-thread-pool.patch b/patches/server/0147-Run-background-executor-tasks-on-base-thread-pool.patch new file mode 100644 index 0000000..f279d2f --- /dev/null +++ b/patches/server/0147-Run-background-executor-tasks-on-base-thread-pool.patch @@ -0,0 +1,63 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Martijn Muijsers +Date: Sun, 29 Jan 2023 23:56:57 +0100 +Subject: [PATCH] Run background executor tasks on base thread pool + +License: AGPL-3.0 (https://www.gnu.org/licenses/agpl-3.0.html) +Gale - https://galemc.org + +diff --git a/src/main/java/net/minecraft/Util.java b/src/main/java/net/minecraft/Util.java +index 5ef58831a857fd8aa4ac30147762dc17d773a53e..6b109d92dec227d4a91a455caf596beb112a8351 100644 +--- a/src/main/java/net/minecraft/Util.java ++++ b/src/main/java/net/minecraft/Util.java +@@ -26,9 +26,6 @@ import java.net.URL; + import java.nio.file.Files; + import java.nio.file.Path; + import java.nio.file.spi.FileSystemProvider; +-import java.security.AccessController; +-import java.security.PrivilegedActionException; +-import java.security.PrivilegedExceptionAction; + import java.time.Duration; + import java.time.Instant; + import java.time.ZonedDateTime; +@@ -47,8 +44,6 @@ import java.util.concurrent.ConcurrentHashMap; + import java.util.concurrent.Executor; + import java.util.concurrent.ExecutorService; + import java.util.concurrent.Executors; +-import java.util.concurrent.ForkJoinPool; +-import java.util.concurrent.ForkJoinWorkerThread; + import java.util.concurrent.LinkedBlockingQueue; + import java.util.concurrent.TimeUnit; + import java.util.concurrent.atomic.AtomicInteger; +@@ -67,11 +62,11 @@ import java.util.stream.Stream; + import javax.annotation.Nullable; + import net.minecraft.resources.ResourceLocation; + import net.minecraft.server.Bootstrap; +-import net.minecraft.util.Mth; + 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.executor.queue.BaseTaskQueues; + import org.slf4j.Logger; + + public class Util { +@@ -79,8 +74,8 @@ public class Util { + private static final int DEFAULT_MAX_THREADS = 255; + 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 = BaseTaskQueues.scheduledAsync.yieldingExecutor; // Gale - base thread pool - remove background executor ++ private static final ExecutorService BOOTSTRAP_EXECUTOR = BACKGROUND_EXECUTOR; // Gale - Patina - remove bootstrap 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 +214,6 @@ public class Util { + } + + public static void shutdownExecutors() { +- shutdownExecutor(BACKGROUND_EXECUTOR); + shutdownExecutor(IO_POOL); + } + diff --git a/patches/server/0148-Run-world-upgrade-tasks-on-base-thread-pool.patch b/patches/server/0148-Run-world-upgrade-tasks-on-base-thread-pool.patch new file mode 100644 index 0000000..29a2718 --- /dev/null +++ b/patches/server/0148-Run-world-upgrade-tasks-on-base-thread-pool.patch @@ -0,0 +1,59 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Martijn Muijsers +Date: Mon, 30 Jan 2023 00:08:14 +0100 +Subject: [PATCH] Run world upgrade tasks on base thread pool + +License: AGPL-3.0 (https://www.gnu.org/licenses/agpl-3.0.html) +Gale - https://galemc.org + +diff --git a/src/main/java/io/papermc/paper/world/ThreadedWorldUpgrader.java b/src/main/java/io/papermc/paper/world/ThreadedWorldUpgrader.java +index 95cac7edae8ac64811fc6a2f6b97dd4a0fceb0b0..a376259202b4a16c67db4d3ef071e0b395aca524 100644 +--- a/src/main/java/io/papermc/paper/world/ThreadedWorldUpgrader.java ++++ b/src/main/java/io/papermc/paper/world/ThreadedWorldUpgrader.java +@@ -7,25 +7,21 @@ import net.minecraft.nbt.CompoundTag; + import net.minecraft.resources.ResourceKey; + import net.minecraft.util.worldupdate.WorldUpgrader; + import net.minecraft.world.level.ChunkPos; +-import net.minecraft.world.level.Level; + import net.minecraft.world.level.chunk.ChunkGenerator; + import net.minecraft.world.level.chunk.storage.ChunkStorage; + import net.minecraft.world.level.chunk.storage.RegionFileStorage; +-import net.minecraft.world.level.dimension.DimensionType; + import net.minecraft.world.level.dimension.LevelStem; +-import net.minecraft.world.level.levelgen.WorldGenSettings; + import net.minecraft.world.level.storage.DimensionDataStorage; + import net.minecraft.world.level.storage.LevelStorageSource; + import org.apache.logging.log4j.LogManager; + import org.apache.logging.log4j.Logger; ++import org.galemc.gale.executor.queue.BaseTaskQueues; ++ + import java.io.File; + import java.io.IOException; + import java.text.DecimalFormat; + import java.util.Optional; + import java.util.concurrent.ExecutorService; +-import java.util.concurrent.Executors; +-import java.util.concurrent.ThreadFactory; +-import java.util.concurrent.atomic.AtomicInteger; + import java.util.concurrent.atomic.AtomicLong; + import java.util.function.Supplier; + +@@ -46,6 +42,10 @@ public class ThreadedWorldUpgrader { + this.dimensionType = dimensionType; + this.worldName = worldName; + this.worldDir = worldDir; ++ // Gale start - base thread pool - remove world upgrade executors ++ this.threadPool = BaseTaskQueues.scheduledAsync.yieldingExecutor; ++ /* ++ // Gale end - base thread pool - remove world upgrade executors + this.threadPool = Executors.newFixedThreadPool(Math.max(1, threads), new ThreadFactory() { + private final AtomicInteger threadCounter = new AtomicInteger(); + +@@ -61,6 +61,7 @@ public class ThreadedWorldUpgrader { + return ret; + } + }); ++ */ // Gale - base thread pool - remove world upgrade executors + this.dataFixer = dataFixer; + this.generatorKey = generatorKey; + this.removeCaches = removeCaches; diff --git a/patches/server/0149-Run-tab-completion-tasks-on-base-thread-pool.patch b/patches/server/0149-Run-tab-completion-tasks-on-base-thread-pool.patch new file mode 100644 index 0000000..f4610cf --- /dev/null +++ b/patches/server/0149-Run-tab-completion-tasks-on-base-thread-pool.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Martijn Muijsers +Date: Mon, 30 Jan 2023 00:11:30 +0100 +Subject: [PATCH] Run tab completion tasks on base thread pool + +License: AGPL-3.0 (https://www.gnu.org/licenses/agpl-3.0.html) +Gale - https://galemc.org + +diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +index f62da01d38533818de70761c82ffb959083e0811..93a533bdeb5108f5c3e758f8062de083283fd075 100644 +--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java ++++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +@@ -884,8 +884,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic + } + + // Paper start +- private static final java.util.concurrent.ExecutorService TAB_COMPLETE_EXECUTOR = java.util.concurrent.Executors.newFixedThreadPool(4, +- new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Tab Complete Thread - #%d").setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build()); ++ private static final java.util.concurrent.ExecutorService TAB_COMPLETE_EXECUTOR = BaseTaskQueues.scheduledAsync.yieldingExecutor; // Gale - base thread pool - remove tab complete executor + // Paper end + @Override + public void handleCustomCommandSuggestions(ServerboundCommandSuggestionPacket packet) { diff --git a/patches/server/0150-Run-text-filter-tasks-on-base-thread-pool.patch b/patches/server/0150-Run-text-filter-tasks-on-base-thread-pool.patch new file mode 100644 index 0000000..7c62678 --- /dev/null +++ b/patches/server/0150-Run-text-filter-tasks-on-base-thread-pool.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Martijn Muijsers +Date: Mon, 30 Jan 2023 00:15:33 +0100 +Subject: [PATCH] Run text filter tasks on base thread pool + +License: AGPL-3.0 (https://www.gnu.org/licenses/agpl-3.0.html) +Gale - https://galemc.org + +diff --git a/src/main/java/net/minecraft/server/network/TextFilterClient.java b/src/main/java/net/minecraft/server/network/TextFilterClient.java +index 4b3d2280326c7eeda4952c36edff141cbff90e16..e684fa1990d631cafd8e84debe52301fc9ed329f 100644 +--- a/src/main/java/net/minecraft/server/network/TextFilterClient.java ++++ b/src/main/java/net/minecraft/server/network/TextFilterClient.java +@@ -23,7 +23,6 @@ import java.util.List; + import java.util.concurrent.CompletableFuture; + import java.util.concurrent.Executor; + import java.util.concurrent.ExecutorService; +-import java.util.concurrent.Executors; + import java.util.concurrent.ThreadFactory; + import java.util.concurrent.atomic.AtomicInteger; + import javax.annotation.Nullable; +@@ -32,6 +31,7 @@ import net.minecraft.Util; + import net.minecraft.network.chat.FilterMask; + import net.minecraft.util.GsonHelper; + import net.minecraft.util.thread.ProcessorMailbox; ++import org.galemc.gale.executor.queue.BaseTaskQueues; + import org.slf4j.Logger; + + public class TextFilterClient implements AutoCloseable { +@@ -62,7 +62,7 @@ public class TextFilterClient implements AutoCloseable { + this.joinEncoder = joinEncoder; + this.leaveEndpoint = leaveEndpoint; + this.leaveEncoder = leaveEncoder; +- this.workerPool = Executors.newFixedThreadPool(parallelism, THREAD_FACTORY); ++ this.workerPool = BaseTaskQueues.scheduledAsync.yieldingExecutor; // Gale - base thread pool - remove text filter executor + } + + private static URL getEndpoint(URI root, @Nullable JsonObject endpoints, String key, String fallback) throws MalformedURLException { diff --git a/patches/server/0147-Run-cleaner-tasks-on-base-thread-pool.patch b/patches/server/0151-Run-cleaner-tasks-on-base-thread-pool.patch similarity index 100% rename from patches/server/0147-Run-cleaner-tasks-on-base-thread-pool.patch rename to patches/server/0151-Run-cleaner-tasks-on-base-thread-pool.patch diff --git a/patches/server/0148-Run-chunk-cache-tasks-on-base-thread-pool.patch b/patches/server/0152-Run-chunk-cache-tasks-on-base-thread-pool.patch similarity index 100% rename from patches/server/0148-Run-chunk-cache-tasks-on-base-thread-pool.patch rename to patches/server/0152-Run-chunk-cache-tasks-on-base-thread-pool.patch diff --git a/patches/server/0149-Run-TickThread-chunk-tasks-on-base-thread-pool.patch b/patches/server/0153-Run-TickThread-chunk-tasks-on-base-thread-pool.patch similarity index 100% rename from patches/server/0149-Run-TickThread-chunk-tasks-on-base-thread-pool.patch rename to patches/server/0153-Run-TickThread-chunk-tasks-on-base-thread-pool.patch diff --git a/patches/server/0150-Non-blocking-PooledObjects.patch b/patches/server/0154-Non-blocking-PooledObjects.patch similarity index 100% rename from patches/server/0150-Non-blocking-PooledObjects.patch rename to patches/server/0154-Non-blocking-PooledObjects.patch