diff options
author | Nassim Jahnke <[email protected]> | 2024-11-28 11:20:18 +0100 |
---|---|---|
committer | Nassim Jahnke <[email protected]> | 2024-11-29 10:03:37 +0100 |
commit | 031ca6dcff86845d0d13524f5a9e1d0c3a7f9841 (patch) | |
tree | 2cad368467a0e0c59681005cf9456a74daa3b829 | |
parent | 9953384d89548c0c53a57e2a60abace9ad19b177 (diff) | |
download | Paper-031ca6dcff86845d0d13524f5a9e1d0c3a7f9841.tar.gz Paper-031ca6dcff86845d0d13524f5a9e1d0c3a7f9841.zip |
Clean up thread pool usage
7 files changed, 87 insertions, 43 deletions
diff --git a/patches/server/0009-MC-Utils.patch b/patches/server/0009-MC-Utils.patch index 2bea8ec9a7..98b049b563 100644 --- a/patches/server/0009-MC-Utils.patch +++ b/patches/server/0009-MC-Utils.patch @@ -4844,10 +4844,10 @@ index 0000000000000000000000000000000000000000..197224e31175252d8438a8df585bbb65 +} diff --git a/src/main/java/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java new file mode 100644 -index 0000000000000000000000000000000000000000..9d97c9afa31bed6d2e6b7778bfe4cc41cea31c4d +index 0000000000000000000000000000000000000000..a4ac34ebb58a404f4fca7e763e61d4ab05ee3af4 --- /dev/null +++ b/src/main/java/io/papermc/paper/util/MCUtil.java -@@ -0,0 +1,209 @@ +@@ -0,0 +1,205 @@ +package io.papermc.paper.util; + +import com.google.common.collect.Collections2; @@ -4861,9 +4861,8 @@ index 0000000000000000000000000000000000000000..9d97c9afa31bed6d2e6b7778bfe4cc41 +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; -+import java.util.concurrent.LinkedBlockingQueue; -+import java.util.concurrent.ThreadPoolExecutor; -+import java.util.concurrent.TimeUnit; ++import java.util.concurrent.ExecutorService; ++import java.util.concurrent.Executors; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Function; @@ -4888,13 +4887,10 @@ index 0000000000000000000000000000000000000000..9d97c9afa31bed6d2e6b7778bfe4cc41 + run.run(); + } + }; -+ public static final ThreadPoolExecutor asyncExecutor = new ThreadPoolExecutor( -+ 2, 2, 60L, TimeUnit.SECONDS, -+ new LinkedBlockingQueue<>(), -+ new ThreadFactoryBuilder() -+ .setNameFormat("Paper Async Task Handler Thread - %1$d") -+ .setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(MinecraftServer.LOGGER)) -+ .build() ++ public static final ExecutorService ASYNC_EXECUTOR = Executors.newFixedThreadPool(2, new ThreadFactoryBuilder() ++ .setNameFormat("Paper Async Task Handler Thread - %1$d") ++ .setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(MinecraftServer.LOGGER)) ++ .build() + ); + + private MCUtil() { @@ -5029,7 +5025,7 @@ index 0000000000000000000000000000000000000000..9d97c9afa31bed6d2e6b7778bfe4cc41 + } + + public static void scheduleAsyncTask(Runnable run) { -+ asyncExecutor.execute(run); ++ ASYNC_EXECUTOR.execute(run); + } + + public static <T> ResourceKey<T> toResourceKey( @@ -5216,15 +5212,15 @@ index 3e5a85a7ad6149b04622c254fbc2e174896a4128..3f662692ed4846e026a9d48595e7b3b2 + } diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 8e16bc7da15824723f1d7d4bff87fac181978500..709330ca9caa82a6de71767b3d5c32f97ea1d68b 100644 +index 8e16bc7da15824723f1d7d4bff87fac181978500..1b6cf839450cc69bd3cda6d874656c5345b0ac51 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -988,6 +988,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa 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 ++ io.papermc.paper.util.MCUtil.ASYNC_EXECUTOR.shutdown(); // Paper ++ try { io.papermc.paper.util.MCUtil.ASYNC_EXECUTOR.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"); diff --git a/patches/server/0259-Improve-Server-Thread-Pool-and-Thread-Priorities.patch b/patches/server/0259-Improve-Server-Thread-Pool-and-Thread-Priorities.patch index c65945b955..5096a0a4a5 100644 --- a/patches/server/0259-Improve-Server-Thread-Pool-and-Thread-Priorities.patch +++ b/patches/server/0259-Improve-Server-Thread-Pool-and-Thread-Priorities.patch @@ -38,7 +38,7 @@ index 0000000000000000000000000000000000000000..b60f59cf5cc8eb84a6055b7861857dec + } +} diff --git a/src/main/java/net/minecraft/Util.java b/src/main/java/net/minecraft/Util.java -index 8cac2075077b1d9c2b01e09c99780ff9e204abb2..bf2833c92eca6491699b4a89410e4e46b5bbe4d1 100644 +index 8cac2075077b1d9c2b01e09c99780ff9e204abb2..dbf79a018260a006bf5d16608b35bcbea9adb963 100644 --- a/src/main/java/net/minecraft/Util.java +++ b/src/main/java/net/minecraft/Util.java @@ -92,7 +92,7 @@ public class Util { @@ -78,7 +78,7 @@ index 8cac2075077b1d9c2b01e09c99780ff9e204abb2..bf2833c92eca6491699b4a89410e4e46 - AtomicInteger atomicInteger = new AtomicInteger(1); - executorService = new ForkJoinPool(i, pool -> { - final String string2 = "Worker-" + name + "-" + atomicInteger.getAndIncrement(); -+ executorService = new java.util.concurrent.ThreadPoolExecutor(i, i,0L, TimeUnit.MILLISECONDS, new java.util.concurrent.LinkedBlockingQueue<>(), target -> new io.papermc.paper.util.ServerWorkerThread(target, s, priorityModifier)); ++ executorService = Executors.newFixedThreadPool(i, target -> new io.papermc.paper.util.ServerWorkerThread(target, s, priorityModifier)); + } + /* final String string2 = "Worker-" + name + "-" + atomicInteger.getAndIncrement(); ForkJoinWorkerThread forkJoinWorkerThread = new ForkJoinWorkerThread(pool) { @@ -94,7 +94,7 @@ index 8cac2075077b1d9c2b01e09c99780ff9e204abb2..bf2833c92eca6491699b4a89410e4e46 return new TracingExecutor(executorService); } diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index c4d8918a7accbe5eb3035b4ec3b423f30c613d60..b54c1ecf3384fba741fa6334caee498b83887508 100644 +index af20a16e18673a629fc3033d8e7e07eba855b1c7..2a4f8075867a302afd98bdf9ac8b11622c29082d 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -332,6 +332,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa diff --git a/patches/server/0273-Async-command-map-building.patch b/patches/server/0273-Async-command-map-building.patch index e4b8563a3d..2d9703c811 100644 --- a/patches/server/0273-Async-command-map-building.patch +++ b/patches/server/0273-Async-command-map-building.patch @@ -9,27 +9,22 @@ commands if the server is restarting. Using the default async pool caused issues due to the shutdown logic generally being much later. diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java -index 2008fd542eaf1c2fac776ae1751c227a3b6dde4b..e812cc865baaa1ee03872f7969ee98600b82483b 100644 +index 2008fd542eaf1c2fac776ae1751c227a3b6dde4b..34564f4118eab9e95176cb4ff4bc93fbe97d9b6b 100644 --- a/src/main/java/net/minecraft/commands/Commands.java +++ b/src/main/java/net/minecraft/commands/Commands.java -@@ -455,6 +455,24 @@ public class Commands { +@@ -455,6 +455,19 @@ public class Commands { if ( org.spigotmc.SpigotConfig.tabComplete < 0 ) return; // Spigot // CraftBukkit start // Register Vanilla commands into builtRoot as before + // Paper start - Perf: Async command map building -+ COMMAND_SENDING_POOL.execute(() -> { -+ this.sendAsync(player); -+ }); ++ COMMAND_SENDING_POOL.execute(() -> this.sendAsync(player)); + } + -+ public static final java.util.concurrent.ThreadPoolExecutor COMMAND_SENDING_POOL = new java.util.concurrent.ThreadPoolExecutor( -+ 0, 2, 60L, java.util.concurrent.TimeUnit.SECONDS, -+ new java.util.concurrent.LinkedBlockingQueue<>(), ++ public static final java.util.concurrent.ExecutorService COMMAND_SENDING_POOL = java.util.concurrent.Executors.newFixedThreadPool(2, + new com.google.common.util.concurrent.ThreadFactoryBuilder() + .setNameFormat("Paper Async Command Builder Thread Pool - %1$d") + .setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)) -+ .build(), -+ new java.util.concurrent.ThreadPoolExecutor.DiscardPolicy() ++ .build() + ); + + private void sendAsync(ServerPlayer player) { @@ -37,7 +32,7 @@ index 2008fd542eaf1c2fac776ae1751c227a3b6dde4b..e812cc865baaa1ee03872f7969ee9860 Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues RootCommandNode vanillaRoot = new RootCommandNode(); -@@ -472,7 +490,14 @@ public class Commands { +@@ -472,7 +485,14 @@ public class Commands { for (CommandNode node : rootcommandnode.getChildren()) { bukkit.add(node.getName()); } @@ -53,7 +48,7 @@ index 2008fd542eaf1c2fac776ae1751c227a3b6dde4b..e812cc865baaa1ee03872f7969ee9860 event.getPlayer().getServer().getPluginManager().callEvent(event); diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 13aa191235ac6bb1d00d89ae29c750595cc6be78..0f1a7b649d398a875b57746530242e3ced595bfd 100644 +index 9a9291282f7ec99be9badf8b32fab5f0ea0f1037..feb45369b41b597fd603c12f3da23759923b6a6d 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -944,6 +944,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa diff --git a/patches/server/0274-Brigadier-Mojang-API.patch b/patches/server/0274-Brigadier-Mojang-API.patch index de560b4742..a6e586dce9 100644 --- a/patches/server/0274-Brigadier-Mojang-API.patch +++ b/patches/server/0274-Brigadier-Mojang-API.patch @@ -87,10 +87,10 @@ index 4d5f1dd1c3bd742b1bc5e3914101a699041caa7e..5316f148f3f9128690f019d544e462b0 public boolean hasPermission(int level) { // CraftBukkit start diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java -index e812cc865baaa1ee03872f7969ee98600b82483b..c847fbdb6f52386570eb4c070fcc01d39cc52151 100644 +index 34564f4118eab9e95176cb4ff4bc93fbe97d9b6b..c2c8193a3b3f7a224b05a09cd65108860aaae814 100644 --- a/src/main/java/net/minecraft/commands/Commands.java +++ b/src/main/java/net/minecraft/commands/Commands.java -@@ -491,6 +491,7 @@ public class Commands { +@@ -486,6 +486,7 @@ public class Commands { bukkit.add(node.getName()); } // Paper start - Perf: Async command map building @@ -98,7 +98,7 @@ index e812cc865baaa1ee03872f7969ee98600b82483b..c847fbdb6f52386570eb4c070fcc01d3 net.minecraft.server.MinecraftServer.getServer().execute(() -> { runSync(player, bukkit, rootcommandnode); }); -@@ -498,6 +499,7 @@ public class Commands { +@@ -493,6 +494,7 @@ public class Commands { private void runSync(ServerPlayer player, Collection<String> bukkit, RootCommandNode<SharedSuggestionProvider> rootcommandnode) { // Paper end - Perf: Async command map building @@ -106,7 +106,7 @@ index e812cc865baaa1ee03872f7969ee98600b82483b..c847fbdb6f52386570eb4c070fcc01d3 PlayerCommandSendEvent event = new PlayerCommandSendEvent(player.getBukkitEntity(), new LinkedHashSet<>(bukkit)); event.getPlayer().getServer().getPluginManager().callEvent(event); -@@ -516,6 +518,11 @@ public class Commands { +@@ -511,6 +513,11 @@ public class Commands { while (iterator.hasNext()) { CommandNode<CommandSourceStack> commandnode2 = (CommandNode) iterator.next(); diff --git a/patches/server/0953-Brigadier-based-command-API.patch b/patches/server/0953-Brigadier-based-command-API.patch index 5296fff1c9..0f4bec1390 100644 --- a/patches/server/0953-Brigadier-based-command-API.patch +++ b/patches/server/0953-Brigadier-based-command-API.patch @@ -2068,7 +2068,7 @@ index fc0c60b22844ed010aede2fa125b9fa440d3de80..3549ffea451b932602efb113844ba21a public org.bukkit.command.CommandSender getBukkitSender() { return this.source.getBukkitSender(this); diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java -index fe9f638db3525893beed565ef9b7ac2fc76318bd..b1571c162fd8ab7239a7f4aafea5187feb694761 100644 +index 26bc8d7075f8a9c411776ab91aeddcd776d21348..2fc5651d1546fd4bb10b0617540e906f483cb36c 100644 --- a/src/main/java/net/minecraft/commands/Commands.java +++ b/src/main/java/net/minecraft/commands/Commands.java @@ -159,7 +159,7 @@ public class Commands { @@ -2135,7 +2135,7 @@ index fe9f638db3525893beed565ef9b7ac2fc76318bd..b1571c162fd8ab7239a7f4aafea5187f StackTraceElement[] astacktraceelement = exception.getStackTrace(); for (int i = 0; i < Math.min(astacktraceelement.length, 3); ++i) { -@@ -478,13 +497,7 @@ public class Commands { +@@ -473,13 +492,7 @@ public class Commands { private void sendAsync(ServerPlayer player) { // Paper end - Perf: Async command map building Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues @@ -2150,7 +2150,7 @@ index fe9f638db3525893beed565ef9b7ac2fc76318bd..b1571c162fd8ab7239a7f4aafea5187f RootCommandNode<SharedSuggestionProvider> rootcommandnode = new RootCommandNode(); map.put(this.dispatcher.getRoot(), rootcommandnode); -@@ -518,6 +531,7 @@ public class Commands { +@@ -513,6 +526,7 @@ public class Commands { } private void fillUsableCommands(CommandNode<CommandSourceStack> tree, CommandNode<SharedSuggestionProvider> result, CommandSourceStack source, Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> resultNodes) { @@ -2158,7 +2158,7 @@ index fe9f638db3525893beed565ef9b7ac2fc76318bd..b1571c162fd8ab7239a7f4aafea5187f Iterator iterator = tree.getChildren().iterator(); while (iterator.hasNext()) { -@@ -531,6 +545,42 @@ public class Commands { +@@ -526,6 +540,42 @@ public class Commands { if (commandnode2.canUse(source)) { ArgumentBuilder argumentbuilder = commandnode2.createBuilder(); // CraftBukkit - decompile error @@ -2218,7 +2218,7 @@ index 55484826fc5ddd04ae024e25a0251796d7fa9c28..237e4f7b24908e9ade9a483eb7ae05fa Component component = message.resolveComponent(commandSourceStack); CommandSigningContext commandSigningContext = commandSourceStack.getSigningContext(); diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 95786d2e1a8ac0fdbe8d449b3f100ac0512ee21e..b13b3991292ab96542ba390f3e8e3ff0d7529c44 100644 +index 9c1e1c049db55e73851e3d513cba25027bd0c3b4..ab1a2c4272c4c84743ff501bb35816d35c9d4c94 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -316,7 +316,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa diff --git a/patches/server/0985-Fix-entity-type-tags-suggestions-in-selectors.patch b/patches/server/0985-Fix-entity-type-tags-suggestions-in-selectors.patch index f29fc5c649..89a9da85e1 100644 --- a/patches/server/0985-Fix-entity-type-tags-suggestions-in-selectors.patch +++ b/patches/server/0985-Fix-entity-type-tags-suggestions-in-selectors.patch @@ -37,10 +37,10 @@ index 3549ffea451b932602efb113844ba21a7bc72371..13bd145b1e8006a53c22f5dc0c78f29b + // Paper end - tell clients to ask server for suggestions for EntityArguments } diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java -index b1571c162fd8ab7239a7f4aafea5187feb694761..1e7b99a82184f73aa31cb2e0d4e52a806240926f 100644 +index 2fc5651d1546fd4bb10b0617540e906f483cb36c..f58275101fd5671bab0aa66875c989e568384647 100644 --- a/src/main/java/net/minecraft/commands/Commands.java +++ b/src/main/java/net/minecraft/commands/Commands.java -@@ -534,6 +534,7 @@ public class Commands { +@@ -529,6 +529,7 @@ public class Commands { resultNodes.keySet().removeIf((node) -> !org.spigotmc.SpigotConfig.sendNamespaced && node.getName().contains( ":" )); // Paper - Remove namedspaced from result nodes to prevent redirect trimming ~ see comment below Iterator iterator = tree.getChildren().iterator(); @@ -48,7 +48,7 @@ index b1571c162fd8ab7239a7f4aafea5187feb694761..1e7b99a82184f73aa31cb2e0d4e52a80 while (iterator.hasNext()) { CommandNode<CommandSourceStack> commandnode2 = (CommandNode) iterator.next(); // Paper start - Brigadier API -@@ -596,6 +597,12 @@ public class Commands { +@@ -591,6 +592,12 @@ public class Commands { if (requiredargumentbuilder.getSuggestionsProvider() != null) { requiredargumentbuilder.suggests(SuggestionProviders.safelySwap(requiredargumentbuilder.getSuggestionsProvider())); diff --git a/patches/server/1073-Separate-dimensiondata-executor.patch b/patches/server/1073-Separate-dimensiondata-executor.patch new file mode 100644 index 0000000000..40c89f1045 --- /dev/null +++ b/patches/server/1073-Separate-dimensiondata-executor.patch @@ -0,0 +1,53 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Nassim Jahnke <[email protected]> +Date: Thu, 28 Nov 2024 10:35:58 +0100 +Subject: [PATCH] Separate dimensiondata executor + + +diff --git a/src/main/java/net/minecraft/Util.java b/src/main/java/net/minecraft/Util.java +index 276ad77ecb274b6cd454d0f92457964a8eaa5824..1360aa8202542d3d0f32247f1123575fc2c38ff1 100644 +--- a/src/main/java/net/minecraft/Util.java ++++ b/src/main/java/net/minecraft/Util.java +@@ -94,6 +94,7 @@ public class Util { + private static final String MAX_THREADS_SYSTEM_PROPERTY = "max.bg.threads"; + private static final TracingExecutor BACKGROUND_EXECUTOR = makeExecutor("Main", -1); // Paper - Perf: add priority + private static final TracingExecutor IO_POOL = makeIoExecutor("IO-Worker-", false); ++ public static final TracingExecutor DIMENSION_DATA_IO_POOL = makeExtraIoExecutor("Dimension-Data-IO-Worker-"); // Paper - Separate dimension data IO pool + private static final TracingExecutor DOWNLOAD_POOL = makeIoExecutor("Download-", true); + // 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() { +@@ -260,6 +261,21 @@ public class Util { + })); + } + ++ // Paper start - Separate dimension data IO pool ++ private static TracingExecutor makeExtraIoExecutor(String namePrefix) { ++ AtomicInteger atomicInteger = new AtomicInteger(1); ++ return new TracingExecutor(Executors.newFixedThreadPool(4, runnable -> { ++ Thread thread = new Thread(runnable); ++ String string2 = namePrefix + atomicInteger.getAndIncrement(); ++ TracyClient.setThreadName(string2, namePrefix.hashCode()); ++ thread.setName(string2); ++ thread.setDaemon(false); ++ thread.setUncaughtExceptionHandler(Util::onThreadException); ++ return thread; ++ })); ++ } ++ // Paper end - Separate dimension data IO pool ++ + public static void throwAsRuntime(Throwable t) { + throw t instanceof RuntimeException ? (RuntimeException)t : new RuntimeException(t); + } +diff --git a/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java b/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java +index d16f124e0371ce943298c8d7d9bfac21e98cf885..8212f2dfba5c2eee5a823b5217fb43dc870d228a 100644 +--- a/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java ++++ b/src/main/java/net/minecraft/world/level/storage/DimensionDataStorage.java +@@ -155,7 +155,7 @@ public class DimensionDataStorage implements AutoCloseable { + } catch (IOException var3) { + LOGGER.error("Could not save data to {}", path.getFileName(), var3); + } +- }, Util.ioPool()); ++ }, Util.DIMENSION_DATA_IO_POOL); // Paper - Separate dimension data IO pool + } + + public void saveAndJoin() { |