Improve Server Thread Pool and Thread Priorities

Use a simple executor since Fork join is a much more complex pool
type and we are not using its capabilities.

Set thread priorities so main thread has above normal priority over
server threads

Allow usage of a single thread executor by not using ForkJoin so single core CPU's
and reduce worldgen thread worker count for low core count CPUs.

== AT ==
public net.minecraft.Util onThreadException(Ljava/lang/Thread;Ljava/lang/Throwable;)V

Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
This commit is contained in:
Aikar 2018-10-23 23:14:38 -04:00
parent 539f1ba018
commit 9902ba8869
3 changed files with 129 additions and 52 deletions

View file

@ -1,7 +1,11 @@
--- a/net/minecraft/Util.java --- a/net/minecraft/Util.java
+++ b/net/minecraft/Util.java +++ b/net/minecraft/Util.java
@@ -95,6 +95,22 @@ @@ -92,9 +92,25 @@
private static final TracingExecutor BACKGROUND_EXECUTOR = makeExecutor("Main"); private static final int DEFAULT_MAX_THREADS = 255;
private static final int DEFAULT_SAFE_FILE_OPERATION_RETRIES = 10;
private static final String MAX_THREADS_SYSTEM_PROPERTY = "max.bg.threads";
- private static final TracingExecutor BACKGROUND_EXECUTOR = makeExecutor("Main");
+ private static final TracingExecutor BACKGROUND_EXECUTOR = makeExecutor("Main", -1); // Paper - Perf: add priority
private static final TracingExecutor IO_POOL = makeIoExecutor("IO-Worker-", false); private static final TracingExecutor IO_POOL = makeIoExecutor("IO-Worker-", false);
private static final TracingExecutor DOWNLOAD_POOL = makeIoExecutor("Download-", true); private static final TracingExecutor DOWNLOAD_POOL = makeIoExecutor("Download-", true);
+ // Paper start - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread + // Paper start - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
@ -32,7 +36,58 @@
} }
public static long getEpochMillis() { public static long getEpochMillis() {
@@ -537,7 +553,7 @@ @@ -147,15 +163,16 @@
return FILENAME_DATE_TIME_FORMATTER.format(ZonedDateTime.now());
}
- private static TracingExecutor makeExecutor(String name) {
+ private static TracingExecutor makeExecutor(String name, final int priorityModifier) { // Paper - Perf: add priority
int i = maxAllowedExecutorThreads();
- ExecutorService executorService;
+ // Paper start - Perf: use simpler thread pool that allows 1 thread and reduce worldgen thread worker count for low core count CPUs
+ final ExecutorService executorService;
if (i <= 0) {
executorService = MoreExecutors.newDirectExecutorService();
} else {
- AtomicInteger atomicInteger = new AtomicInteger(1);
- executorService = new ForkJoinPool(i, pool -> {
- final String string2 = "Worker-" + name + "-" + atomicInteger.getAndIncrement();
+ executorService = Executors.newFixedThreadPool(i, target -> new io.papermc.paper.util.ServerWorkerThread(target, name, priorityModifier));
+ }
+ /* final String string2 = "Worker-" + name + "-" + atomicInteger.getAndIncrement();
ForkJoinWorkerThread forkJoinWorkerThread = new ForkJoinWorkerThread(pool) {
@Override
protected void onStart() {
@@ -177,13 +194,26 @@
forkJoinWorkerThread.setName(string2);
return forkJoinWorkerThread;
}, Util::onThreadException, true);
- }
+ }*/
return new TracingExecutor(executorService);
}
public static int maxAllowedExecutorThreads() {
- return Mth.clamp(Runtime.getRuntime().availableProcessors() - 1, 1, getMaxThreads());
+ // Paper start - Perf: use simpler thread pool that allows 1 thread and reduce worldgen thread worker count for low core count CPUs
+ final int cpus = Runtime.getRuntime().availableProcessors() / 2;
+ int maxExecutorThreads;
+ if (cpus <= 4) {
+ maxExecutorThreads = cpus <= 2 ? 1 : 2;
+ } else if (cpus <= 8) {
+ // [5, 8]
+ maxExecutorThreads = Math.max(3, cpus - 2);
+ } else {
+ maxExecutorThreads = cpus * 2 / 3;
+ }
+ maxExecutorThreads = Math.min(8, maxExecutorThreads);
+ return Integer.getInteger("Paper.WorkerThreadCount", maxExecutorThreads);
+ // Paper end - Perf: use simpler thread pool that allows 1 thread and reduce worldgen thread worker count for low core count CPUs
}
private static int getMaxThreads() {
@@ -537,7 +567,7 @@
public static <K extends Enum<K>, V> EnumMap<K, V> makeEnumMap(Class<K> enumClass, Function<K, V> mapper) { public static <K extends Enum<K>, V> EnumMap<K, V> makeEnumMap(Class<K> enumClass, Function<K, V> mapper) {
EnumMap<K, V> enumMap = new EnumMap<>(enumClass); EnumMap<K, V> enumMap = new EnumMap<>(enumClass);

View file

@ -169,7 +169,12 @@
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) { public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
AtomicReference<S> atomicreference = new AtomicReference(); AtomicReference<S> atomicreference = new AtomicReference();
Thread thread = new Thread(() -> { Thread thread = new Thread(() -> {
@@ -290,15 +336,16 @@ @@ -286,19 +332,21 @@
thread.setUncaughtExceptionHandler((thread1, throwable) -> {
MinecraftServer.LOGGER.error("Uncaught exception in server thread", throwable);
});
+ thread.setPriority(Thread.NORM_PRIORITY+2); // Paper - Perf: Boost priority
if (Runtime.getRuntime().availableProcessors() > 4) {
thread.setPriority(8); thread.setPriority(8);
} }
@ -188,7 +193,7 @@
this.metricsRecorder = InactiveMetricsRecorder.INSTANCE; this.metricsRecorder = InactiveMetricsRecorder.INSTANCE;
this.onMetricsRecordingStopped = (methodprofilerresults) -> { this.onMetricsRecordingStopped = (methodprofilerresults) -> {
this.stopRecordingMetrics(); this.stopRecordingMetrics();
@@ -319,36 +366,68 @@ @@ -319,36 +367,68 @@
this.scoreboard = new ServerScoreboard(this); this.scoreboard = new ServerScoreboard(this);
this.customBossEvents = new CustomBossEvents(); this.customBossEvents = new CustomBossEvents();
this.suppressedExceptions = new SuppressedExceptionCollector(); this.suppressedExceptions = new SuppressedExceptionCollector();
@ -272,7 +277,7 @@
} }
private void readScoreboard(DimensionDataStorage persistentStateManager) { private void readScoreboard(DimensionDataStorage persistentStateManager) {
@@ -357,7 +436,7 @@ @@ -357,7 +437,7 @@
protected abstract boolean initServer() throws IOException; protected abstract boolean initServer() throws IOException;
@ -281,7 +286,7 @@
if (!JvmProfiler.INSTANCE.isRunning()) { if (!JvmProfiler.INSTANCE.isRunning()) {
; ;
} }
@@ -365,12 +444,8 @@ @@ -365,12 +445,8 @@
boolean flag = false; boolean flag = false;
ProfiledDuration profiledduration = JvmProfiler.INSTANCE.onWorldLoadedStarted(); ProfiledDuration profiledduration = JvmProfiler.INSTANCE.onWorldLoadedStarted();
@ -295,7 +300,7 @@
if (profiledduration != null) { if (profiledduration != null) {
profiledduration.finish(true); profiledduration.finish(true);
} }
@@ -387,23 +462,232 @@ @@ -387,23 +463,232 @@
protected void forceDifficulty() {} protected void forceDifficulty() {}
@ -542,7 +547,7 @@
if (!iworlddataserver.isInitialized()) { if (!iworlddataserver.isInitialized()) {
try { try {
@@ -427,30 +711,8 @@ @@ -427,30 +712,8 @@
iworlddataserver.setInitialized(true); iworlddataserver.setInitialized(true);
} }
@ -574,7 +579,7 @@
private static void setInitialSpawn(ServerLevel world, ServerLevelData worldProperties, boolean bonusChest, boolean debugWorld) { private static void setInitialSpawn(ServerLevel world, ServerLevelData worldProperties, boolean bonusChest, boolean debugWorld) {
if (debugWorld) { if (debugWorld) {
@@ -458,6 +720,21 @@ @@ -458,6 +721,21 @@
} else { } else {
ServerChunkCache chunkproviderserver = world.getChunkSource(); ServerChunkCache chunkproviderserver = world.getChunkSource();
ChunkPos chunkcoordintpair = new ChunkPos(chunkproviderserver.randomState().sampler().findSpawnPosition()); ChunkPos chunkcoordintpair = new ChunkPos(chunkproviderserver.randomState().sampler().findSpawnPosition());
@ -596,7 +601,7 @@
int i = chunkproviderserver.getGenerator().getSpawnHeight(world); int i = chunkproviderserver.getGenerator().getSpawnHeight(world);
if (i < world.getMinY()) { if (i < world.getMinY()) {
@@ -516,31 +793,36 @@ @@ -516,31 +794,36 @@
iworlddataserver.setGameType(GameType.SPECTATOR); iworlddataserver.setGameType(GameType.SPECTATOR);
} }
@ -644,7 +649,7 @@
ForcedChunksSavedData forcedchunk = (ForcedChunksSavedData) worldserver1.getDataStorage().get(ForcedChunksSavedData.factory(), "chunks"); ForcedChunksSavedData forcedchunk = (ForcedChunksSavedData) worldserver1.getDataStorage().get(ForcedChunksSavedData.factory(), "chunks");
if (forcedchunk != null) { if (forcedchunk != null) {
@@ -555,10 +837,17 @@ @@ -555,10 +838,17 @@
} }
} }
@ -666,7 +671,7 @@
} }
public GameType getDefaultGameType() { public GameType getDefaultGameType() {
@@ -588,12 +877,16 @@ @@ -588,12 +878,16 @@
worldserver.save((ProgressListener) null, flush, worldserver.noSave && !force); worldserver.save((ProgressListener) null, flush, worldserver.noSave && !force);
} }
@ -685,7 +690,7 @@
if (flush) { if (flush) {
Iterator iterator1 = this.getAllLevels().iterator(); Iterator iterator1 = this.getAllLevels().iterator();
@@ -628,18 +921,41 @@ @@ -628,18 +922,41 @@
this.stopServer(); this.stopServer();
} }
@ -728,7 +733,7 @@
} }
MinecraftServer.LOGGER.info("Saving worlds"); MinecraftServer.LOGGER.info("Saving worlds");
@@ -693,6 +1009,15 @@ @@ -693,6 +1010,15 @@
} catch (IOException ioexception1) { } catch (IOException ioexception1) {
MinecraftServer.LOGGER.error("Failed to unlock level {}", this.storageSource.getLevelId(), ioexception1); MinecraftServer.LOGGER.error("Failed to unlock level {}", this.storageSource.getLevelId(), ioexception1);
} }
@ -744,7 +749,7 @@
} }
@@ -709,6 +1034,12 @@ @@ -709,16 +1035,80 @@
} }
public void halt(boolean waitForShutdown) { public void halt(boolean waitForShutdown) {
@ -757,10 +762,14 @@
this.running = false; this.running = false;
if (waitForShutdown) { if (waitForShutdown) {
try { try {
@@ -720,6 +1051,64 @@ this.serverThread.join();
} catch (InterruptedException interruptedexception) {
} MinecraftServer.LOGGER.error("Error while shutting down", interruptedexception);
+ }
+ }
+
+ }
+
+ // Spigot Start + // Spigot Start
+ private static double calcTps(double avg, double exp, double tps) + private static double calcTps(double avg, double exp, double tps)
+ { + {
@ -793,9 +802,9 @@
+ for (int i = 0; i < size; i++) { + for (int i = 0; i < size; i++) {
+ this.samples[i] = dec(TPS); + this.samples[i] = dec(TPS);
+ this.times[i] = SEC_IN_NANO; + this.times[i] = SEC_IN_NANO;
+ } }
+ } }
+
+ private static java.math.BigDecimal dec(long t) { + private static java.math.BigDecimal dec(long t) {
+ return new java.math.BigDecimal(t); + return new java.math.BigDecimal(t);
+ } + }
@ -814,15 +823,14 @@
+ public double getAverage() { + public double getAverage() {
+ return total.divide(dec(time), 30, java.math.RoundingMode.HALF_UP).doubleValue(); + return total.divide(dec(time), 30, java.math.RoundingMode.HALF_UP).doubleValue();
+ } + }
+ } }
+ private static final java.math.BigDecimal TPS_BASE = new java.math.BigDecimal(1E9).multiply(new java.math.BigDecimal(SAMPLE_INTERVAL)); + private static final java.math.BigDecimal TPS_BASE = new java.math.BigDecimal(1E9).multiply(new java.math.BigDecimal(SAMPLE_INTERVAL));
+ // Paper end + // Paper end
+ // Spigot End + // Spigot End
+
protected void runServer() { protected void runServer() {
try { try {
if (!this.initServer()) { @@ -727,9 +1117,16 @@
@@ -727,9 +1116,16 @@
} }
this.nextTickTimeNanos = Util.getNanos(); this.nextTickTimeNanos = Util.getNanos();
@ -840,7 +848,7 @@
while (this.running) { while (this.running) {
long i; long i;
@@ -744,11 +1140,30 @@ @@ -744,11 +1141,30 @@
if (j > MinecraftServer.OVERLOADED_THRESHOLD_NANOS + 20L * i && this.nextTickTimeNanos - this.lastOverloadWarningNanos >= MinecraftServer.OVERLOADED_WARNING_INTERVAL_NANOS + 100L * i) { if (j > MinecraftServer.OVERLOADED_THRESHOLD_NANOS + 20L * i && this.nextTickTimeNanos - this.lastOverloadWarningNanos >= MinecraftServer.OVERLOADED_WARNING_INTERVAL_NANOS + 100L * i) {
long k = j / i; long k = j / i;
@ -871,7 +879,7 @@
boolean flag = i == 0L; boolean flag = i == 0L;
@@ -757,6 +1172,8 @@ @@ -757,6 +1173,8 @@
this.debugCommandProfiler = new MinecraftServer.TimeProfiler(Util.getNanos(), this.tickCount); this.debugCommandProfiler = new MinecraftServer.TimeProfiler(Util.getNanos(), this.tickCount);
} }
@ -880,7 +888,7 @@
this.nextTickTimeNanos += i; this.nextTickTimeNanos += i;
try { try {
@@ -830,6 +1247,13 @@ @@ -830,6 +1248,13 @@
this.services.profileCache().clearExecutor(); this.services.profileCache().clearExecutor();
} }
@ -894,7 +902,7 @@
this.onServerExit(); this.onServerExit();
} }
@@ -889,9 +1313,16 @@ @@ -889,9 +1314,16 @@
} }
private boolean haveTime() { private boolean haveTime() {
@ -912,7 +920,7 @@
public static boolean throwIfFatalException() { public static boolean throwIfFatalException() {
RuntimeException runtimeexception = (RuntimeException) MinecraftServer.fatalException.get(); RuntimeException runtimeexception = (RuntimeException) MinecraftServer.fatalException.get();
@@ -903,7 +1334,7 @@ @@ -903,7 +1335,7 @@
} }
public static void setFatalException(RuntimeException exception) { public static void setFatalException(RuntimeException exception) {
@ -921,7 +929,7 @@
} }
@Override @Override
@@ -977,7 +1408,7 @@ @@ -977,7 +1409,7 @@
} }
} }
@ -930,7 +938,7 @@
Profiler.get().incrementCounter("runTask"); Profiler.get().incrementCounter("runTask");
super.doRunTask(ticktask); super.doRunTask(ticktask);
} }
@@ -1025,6 +1456,7 @@ @@ -1025,6 +1457,7 @@
} }
public void tickServer(BooleanSupplier shouldKeepTicking) { public void tickServer(BooleanSupplier shouldKeepTicking) {
@ -938,7 +946,7 @@
long i = Util.getNanos(); long i = Util.getNanos();
int j = this.pauseWhileEmptySeconds() * 20; int j = this.pauseWhileEmptySeconds() * 20;
@@ -1041,6 +1473,7 @@ @@ -1041,6 +1474,7 @@
this.autoSave(); this.autoSave();
} }
@ -946,7 +954,7 @@
this.tickConnection(); this.tickConnection();
return; return;
} }
@@ -1055,12 +1488,13 @@ @@ -1055,12 +1489,13 @@
} }
--this.ticksUntilAutosave; --this.ticksUntilAutosave;
@ -961,7 +969,7 @@
gameprofilerfiller.push("tallying"); gameprofilerfiller.push("tallying");
long k = Util.getNanos() - i; long k = Util.getNanos() - i;
int l = this.tickCount % 100; int l = this.tickCount % 100;
@@ -1074,7 +1508,7 @@ @@ -1074,7 +1509,7 @@
} }
private void autoSave() { private void autoSave() {
@ -970,7 +978,7 @@
MinecraftServer.LOGGER.debug("Autosave started"); MinecraftServer.LOGGER.debug("Autosave started");
ProfilerFiller gameprofilerfiller = Profiler.get(); ProfilerFiller gameprofilerfiller = Profiler.get();
@@ -1123,7 +1557,7 @@ @@ -1123,7 +1558,7 @@
private ServerStatus buildServerStatus() { private ServerStatus buildServerStatus() {
ServerStatus.Players serverping_serverpingplayersample = this.buildPlayerStatus(); ServerStatus.Players serverping_serverpingplayersample = this.buildPlayerStatus();
@ -979,7 +987,7 @@
} }
private ServerStatus.Players buildPlayerStatus() { private ServerStatus.Players buildPlayerStatus() {
@@ -1133,7 +1567,7 @@ @@ -1133,7 +1568,7 @@
if (this.hidesOnlinePlayers()) { if (this.hidesOnlinePlayers()) {
return new ServerStatus.Players(i, list.size(), List.of()); return new ServerStatus.Players(i, list.size(), List.of());
} else { } else {
@ -988,7 +996,7 @@
ObjectArrayList<GameProfile> objectarraylist = new ObjectArrayList(j); ObjectArrayList<GameProfile> objectarraylist = new ObjectArrayList(j);
int k = Mth.nextInt(this.random, 0, list.size() - j); int k = Mth.nextInt(this.random, 0, list.size() - j);
@@ -1154,24 +1588,43 @@ @@ -1154,24 +1589,43 @@
this.getPlayerList().getPlayers().forEach((entityplayer) -> { this.getPlayerList().getPlayers().forEach((entityplayer) -> {
entityplayer.connection.suspendFlushing(); entityplayer.connection.suspendFlushing();
}); });
@ -1032,7 +1040,7 @@
gameprofilerfiller.push("tick"); gameprofilerfiller.push("tick");
@@ -1186,6 +1639,7 @@ @@ -1186,6 +1640,7 @@
gameprofilerfiller.pop(); gameprofilerfiller.pop();
gameprofilerfiller.pop(); gameprofilerfiller.pop();
@ -1040,7 +1048,7 @@
} }
gameprofilerfiller.popPush("connection"); gameprofilerfiller.popPush("connection");
@@ -1265,8 +1719,24 @@ @@ -1265,8 +1720,24 @@
@Nullable @Nullable
public ServerLevel getLevel(ResourceKey<Level> key) { public ServerLevel getLevel(ResourceKey<Level> key) {
return (ServerLevel) this.levels.get(key); return (ServerLevel) this.levels.get(key);
@ -1065,7 +1073,7 @@
public Set<ResourceKey<Level>> levelKeys() { public Set<ResourceKey<Level>> levelKeys() {
return this.levels.keySet(); return this.levels.keySet();
} }
@@ -1296,7 +1766,7 @@ @@ -1296,7 +1767,7 @@
@DontObfuscate @DontObfuscate
public String getServerModName() { public String getServerModName() {
@ -1074,7 +1082,7 @@
} }
public SystemReport fillSystemReport(SystemReport details) { public SystemReport fillSystemReport(SystemReport details) {
@@ -1347,7 +1817,7 @@ @@ -1347,7 +1818,7 @@
@Override @Override
public void sendSystemMessage(Component message) { public void sendSystemMessage(Component message) {
@ -1083,7 +1091,7 @@
} }
public KeyPair getKeyPair() { public KeyPair getKeyPair() {
@@ -1481,10 +1951,20 @@ @@ -1481,10 +1952,20 @@
@Override @Override
public String getMotd() { public String getMotd() {
@ -1105,7 +1113,7 @@
this.motd = motd; this.motd = motd;
} }
@@ -1507,7 +1987,7 @@ @@ -1507,7 +1988,7 @@
} }
public ServerConnectionListener getConnection() { public ServerConnectionListener getConnection() {
@ -1114,7 +1122,7 @@
} }
public boolean isReady() { public boolean isReady() {
@@ -1634,11 +2114,11 @@ @@ -1634,11 +2115,11 @@
public CompletableFuture<Void> reloadResources(Collection<String> dataPacks) { public CompletableFuture<Void> reloadResources(Collection<String> dataPacks) {
CompletableFuture<Void> completablefuture = CompletableFuture.supplyAsync(() -> { CompletableFuture<Void> completablefuture = CompletableFuture.supplyAsync(() -> {
@ -1128,7 +1136,7 @@
}, this).thenCompose((immutablelist) -> { }, this).thenCompose((immutablelist) -> {
MultiPackResourceManager resourcemanager = new MultiPackResourceManager(PackType.SERVER_DATA, immutablelist); MultiPackResourceManager resourcemanager = new MultiPackResourceManager(PackType.SERVER_DATA, immutablelist);
List<Registry.PendingTags<?>> list = TagLoader.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess()); List<Registry.PendingTags<?>> list = TagLoader.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess());
@@ -1654,6 +2134,7 @@ @@ -1654,6 +2135,7 @@
}).thenAcceptAsync((minecraftserver_reloadableresources) -> { }).thenAcceptAsync((minecraftserver_reloadableresources) -> {
this.resources.close(); this.resources.close();
this.resources = minecraftserver_reloadableresources; this.resources = minecraftserver_reloadableresources;
@ -1136,7 +1144,7 @@
this.packRepository.setSelected(dataPacks); this.packRepository.setSelected(dataPacks);
WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(MinecraftServer.getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures()); WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(MinecraftServer.getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures());
@@ -1952,7 +2433,7 @@ @@ -1952,7 +2434,7 @@
final List<String> list = Lists.newArrayList(); final List<String> list = Lists.newArrayList();
final GameRules gamerules = this.getGameRules(); final GameRules gamerules = this.getGameRules();
@ -1145,7 +1153,7 @@
@Override @Override
public <T extends GameRules.Value<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> type) { public <T extends GameRules.Value<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> type) {
list.add(String.format(Locale.ROOT, "%s=%s\n", key.getId(), gamerules.getRule(key))); list.add(String.format(Locale.ROOT, "%s=%s\n", key.getId(), gamerules.getRule(key)));
@@ -2058,7 +2539,7 @@ @@ -2058,7 +2540,7 @@
try { try {
label51: label51:
{ {
@ -1154,7 +1162,7 @@
try { try {
arraylist = Lists.newArrayList(NativeModuleLister.listModules()); arraylist = Lists.newArrayList(NativeModuleLister.listModules());
@@ -2108,6 +2589,21 @@ @@ -2108,6 +2590,21 @@
} }
@ -1176,7 +1184,7 @@
private ProfilerFiller createProfiler() { private ProfilerFiller createProfiler() {
if (this.willStartRecordingMetrics) { if (this.willStartRecordingMetrics) {
this.metricsRecorder = ActiveMetricsRecorder.createStarted(new ServerMetricsSamplersProvider(Util.timeSource, this.isDedicatedServer()), Util.timeSource, Util.ioPool(), new MetricsPersister("server"), this.onMetricsRecordingStopped, (path) -> { this.metricsRecorder = ActiveMetricsRecorder.createStarted(new ServerMetricsSamplersProvider(Util.timeSource, this.isDedicatedServer()), Util.timeSource, Util.ioPool(), new MetricsPersister("server"), this.onMetricsRecordingStopped, (path) -> {
@@ -2225,18 +2721,24 @@ @@ -2225,18 +2722,24 @@
} }
public void logChatMessage(Component message, ChatType.Bound params, @Nullable String prefix) { public void logChatMessage(Component message, ChatType.Bound params, @Nullable String prefix) {

View file

@ -0,0 +1,14 @@
package io.papermc.paper.util;
import java.util.concurrent.atomic.AtomicInteger;
import net.minecraft.Util;
public class ServerWorkerThread extends Thread {
private static final AtomicInteger threadId = new AtomicInteger(1);
public ServerWorkerThread(Runnable target, String poolName, int prioritityModifier) {
super(target, "Worker-" + poolName + "-" + threadId.getAndIncrement());
setPriority(Thread.NORM_PRIORITY+prioritityModifier); // Deprioritize over main
this.setDaemon(true);
this.setUncaughtExceptionHandler(Util::onThreadException);
}
}