From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar Date: Tue, 23 Oct 2018 23:14:38 -0400 Subject: [PATCH] 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. diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index a7be2875faa968d2e3939974f62c977ca03e9c5b..29f7e78fc21ccca1a080055fe616996d1ede666f 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -176,6 +176,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant { + if (throwable instanceof CompletionException) { + throwable = throwable.getCause(); + } + + if (throwable instanceof ReportedException) { + DispenserRegistry.a(((ReportedException) throwable).a().e()); + System.exit(-1); + } + + MinecraftServer.LOGGER.error(String.format("Caught exception in thread %s", thread), throwable); + }); + } +} diff --git a/src/main/java/net/minecraft/server/SystemUtils.java b/src/main/java/net/minecraft/server/SystemUtils.java index 275c1d2d1eb2649de9a9b5aece6e88c21362efba..3299ac0b0115cb1166c1ee449bd49292e553b7af 100644 --- a/src/main/java/net/minecraft/server/SystemUtils.java +++ b/src/main/java/net/minecraft/server/SystemUtils.java @@ -76,14 +76,17 @@ public class SystemUtils { } private static ExecutorService a(String s) { - int i = MathHelper.clamp(Runtime.getRuntime().availableProcessors() - 1, 1, 7); - Object object; + // Paper start - use simpler thread pool that allows 1 thread + int i = Math.min(8, Math.max(Runtime.getRuntime().availableProcessors() - 2, 1)); + i = Integer.getInteger("Paper.WorkerThreadCount", i); + ExecutorService object; if (i <= 0) { object = MoreExecutors.newDirectExecutorService(); } else { - object = new ForkJoinPool(i, (forkjoinpool) -> { - ForkJoinWorkerThread forkjoinworkerthread = new ForkJoinWorkerThread(forkjoinpool) { + object = new java.util.concurrent.ThreadPoolExecutor(i, i,0L, TimeUnit.MILLISECONDS, new java.util.concurrent.LinkedBlockingQueue(), ServerWorkerThread::new); + } + /* protected void onTermination(Throwable throwable) { if (throwable != null) { SystemUtils.LOGGER.warn("{} died", this.getName(), throwable); @@ -99,6 +102,7 @@ public class SystemUtils { return forkjoinworkerthread; }, SystemUtils::a, true); } + }*/ // Paper end return (ExecutorService) object; }