mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 07:08:47 +01:00
8c5b837e05
Firstly, the old methods all routed to the CompletableFuture method. However, the CF method could not guarantee that if the caller was off-main that the future would be "completed" on-main. Since the callback methods used the CF one, this meant that the callback methods did not guarantee that the callbacks were to be called on the main thread. Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb) so that the methods with the callback are guaranteed to invoke the callback on the main thread. The CF behavior remains unchanged; it may still appear to complete on main if invoked off-main. Secondly, remove the scheduleOnMain invocation in the async chunk completion. This unnecessarily delays the callback by 1 tick. Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which will load chunks within an area. This method is provided as a helper as keeping all chunks loaded within an area can be complicated to implement for plugins (due to the lacking ticket API), and is already implemented internally anyways. Fourthly, remove the ticket addition that occured with getChunkAt and getChunkAtAsync. The ticket addition may delay the unloading of the chunk unnecessarily. It also fixes a very rare timing bug where the future/callback would be completed after the chunk unloads.
47 lines
3 KiB
Diff
47 lines
3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Shane Freeder <theboyetronic@gmail.com>
|
|
Date: Sun, 18 Sep 2022 06:33:17 +0100
|
|
Subject: [PATCH] Configurable chat thread limit
|
|
|
|
By default, spigot shifts chat over to an unbounded thread pool,
|
|
on a normal server, this really offers no gains, the creation of a thread
|
|
on submitting to the pool on these servers eats more time vs just running it in
|
|
the netty pipeline, however, on servers using plugins which do work in here, there
|
|
could be some overall benefits to moving this stuff outside of the pipeline.
|
|
|
|
In general, this patch does two things:
|
|
1) Exposes the core size for the pool, this allows for ensuring that a number of threads
|
|
sit around in the pool, mitigating the need for creating new threads; This IS however
|
|
caveated, the ThreadPoolExecutor will ONLY create core threads as they're needed, it
|
|
just won't allow for us to dip back under the # of core threads, this can potentially
|
|
be mitigated by calling prestartCoreThread, however, I'm not sure if there is much justification
|
|
for this
|
|
2) Exposes a max size for the pool, as stated, by default this is unbounded, for most
|
|
servers limiting the size of the pool is going to have 0 effects given how fast chat
|
|
is actually processed, this is honestly really just exposed for the misnomers or people
|
|
who just wanna ensure that this won't grow over a specific size if chat gets stupidly active
|
|
|
|
diff --git a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
|
|
index c3fe4481dd35f80815716e48beeeb07b1f51e30b..56798215644d8bca1695856b3a941e8089f49e48 100644
|
|
--- a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
|
|
+++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
|
|
@@ -302,7 +302,18 @@ public class GlobalConfiguration extends ConfigurationPart {
|
|
|
|
@PostProcess
|
|
private void postProcess() {
|
|
- // TODO: fill in separate patch
|
|
+ //noinspection ConstantConditions
|
|
+ if (net.minecraft.server.MinecraftServer.getServer() == null) return; // In testing env, this will be null here
|
|
+ int _chatExecutorMaxSize = (this.chatExecutorMaxSize <= 0) ? Integer.MAX_VALUE : this.chatExecutorMaxSize; // This is somewhat dumb, but, this is the default, do we cap this?;
|
|
+ int _chatExecutorCoreSize = Math.max(this.chatExecutorCoreSize, 0);
|
|
+
|
|
+ if (_chatExecutorMaxSize < _chatExecutorCoreSize) {
|
|
+ _chatExecutorMaxSize = _chatExecutorCoreSize;
|
|
+ }
|
|
+
|
|
+ java.util.concurrent.ThreadPoolExecutor executor = (java.util.concurrent.ThreadPoolExecutor) net.minecraft.server.MinecraftServer.getServer().chatExecutor;
|
|
+ executor.setCorePoolSize(_chatExecutorCoreSize);
|
|
+ executor.setMaximumPoolSize(_chatExecutorMaxSize);
|
|
}
|
|
}
|
|
public int maxJoinsPerTick = 5;
|