From cbf16b353dc28b80b1e12407695c597a184d341e Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Fri, 13 Dec 2013 11:58:58 +1100 Subject: [PATCH] Configurable Amount of Netty Threads This brings back the option that the Spigot version of netty saw. By default Netty will try and use cores*2 threads, however if running multiple servers on the same machine, this can be too many threads. Additionally some people have 16 core servers. If 32 Netty threads are allowed in this setup, then the lock contention, and thus blocking between threads becomes much greater, leading to decreased performance. By: md_5 --- .../server/MinecraftServer.java.patch | 53 +++++++++++-------- .../main/java/org/spigotmc/SpigotConfig.java | 7 +++ 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/server/MinecraftServer.java.patch b/paper-server/patches/sources/net/minecraft/server/MinecraftServer.java.patch index 82932a62e8..cb55ff69c7 100644 --- a/paper-server/patches/sources/net/minecraft/server/MinecraftServer.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/MinecraftServer.java.patch @@ -169,7 +169,8 @@ + services.profileCache().setExecutor(this); } - this.connection = new ServerConnectionListener(this); +- this.connection = new ServerConnectionListener(this); ++ // this.connection = new ServerConnection(this); // Spigot this.tickRateManager = new ServerTickRateManager(this); - this.progressListenerFactory = worldGenerationProgressListenerFactory; - this.storageSource = session; @@ -620,11 +621,10 @@ if (flush) { Iterator iterator1 = this.getAllLevels().iterator(); -@@ -627,19 +891,41 @@ - public void close() { +@@ -628,18 +892,40 @@ this.stopServer(); } -+ + + // CraftBukkit start + private boolean hasStopped = false; + private final Object stopLock = new Object(); @@ -634,7 +634,7 @@ + } + } + // CraftBukkit end - ++ public void stopServer() { + // CraftBukkit start - prevent double stopping on multiple threads + synchronized(this.stopLock) { @@ -804,7 +804,7 @@ + SpigotTimings.commandFunctionsTimer.stopTiming(); // Spigot gameprofilerfiller.popPush("levels"); Iterator iterator = this.getAllLevels().iterator(); -+ + + // CraftBukkit start + // Run tasks that are waiting on processing + SpigotTimings.processQueueTimer.startTiming(); // Spigot @@ -812,7 +812,7 @@ + this.processQueue.remove().run(); + } + SpigotTimings.processQueueTimer.stopTiming(); // Spigot - ++ + SpigotTimings.timeUpdateTimer.startTiming(); // Spigot + // Send time updates to everyone, it will get the right time from the world the player is in. + if (this.tickCount % 20 == 0) { @@ -872,12 +872,10 @@ gameprofilerfiller.popPush("send chunks"); iterator = this.playerList.getPlayers().iterator(); -@@ -1265,7 +1607,23 @@ - @Nullable - public ServerLevel getLevel(ResourceKey key) { +@@ -1267,6 +1609,22 @@ return (ServerLevel) this.levels.get(key); -+ } -+ + } + + // CraftBukkit start + public void addLevel(ServerLevel level) { + Map, ServerLevel> oldLevels = this.levels; @@ -891,11 +889,12 @@ + Map, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels); + newLevels.remove(level.dimension()); + this.levels = Collections.unmodifiableMap(newLevels); - } ++ } + // CraftBukkit end - ++ public Set> levelKeys() { return this.levels.keySet(); + } @@ -1296,7 +1654,7 @@ @DontObfuscate @@ -905,6 +904,15 @@ } public SystemReport fillSystemReport(SystemReport details) { +@@ -1507,7 +1865,7 @@ + } + + public ServerConnectionListener getConnection() { +- return this.connection; ++ return this.connection == null ? this.connection = new ServerConnectionListener(this) : this.connection; // Spigot + } + + public boolean isReady() { @@ -1634,11 +1992,11 @@ public CompletableFuture reloadResources(Collection dataPacks) { @@ -945,20 +953,23 @@ try { arraylist = Lists.newArrayList(NativeModuleLister.listModules()); -@@ -2108,6 +2467,22 @@ - - } - +@@ -2105,9 +2464,25 @@ + if (bufferedwriter != null) { + bufferedwriter.close(); + } ++ ++ } ++ + // CraftBukkit start + public boolean isDebugging() { + return false; + } -+ + + @Deprecated + public static MinecraftServer getServer() { + return (Bukkit.getServer() instanceof CraftServer) ? ((CraftServer) Bukkit.getServer()).getServer() : null; -+ } -+ + } + + @Deprecated + public static RegistryAccess getDefaultRegistryAccess() { + return CraftRegistry.getMinecraftRegistry(); diff --git a/paper-server/src/main/java/org/spigotmc/SpigotConfig.java b/paper-server/src/main/java/org/spigotmc/SpigotConfig.java index b48f273709..42c22e09de 100644 --- a/paper-server/src/main/java/org/spigotmc/SpigotConfig.java +++ b/paper-server/src/main/java/org/spigotmc/SpigotConfig.java @@ -224,4 +224,11 @@ public class SpigotConfig } SpigotConfig.bungee = SpigotConfig.getBoolean( "settings.bungeecord", false ); } + + private static void nettyThreads() + { + int count = SpigotConfig.getInt( "settings.netty-threads", 4 ); + System.setProperty( "io.netty.eventLoopThreads", Integer.toString( count ) ); + Bukkit.getLogger().log( Level.INFO, "Using {0} threads for Netty based IO", count ); + } }