From dba368d16f0d2556a1cbc4f177fa48ccf788b5ed Mon Sep 17 00:00:00 2001 From: TheMode Date: Wed, 21 Apr 2021 17:14:40 +0200 Subject: [PATCH] Thread count should depend on the processor count --- src/main/java/net/minestom/server/UpdateManager.java | 5 ++--- .../net/minestom/server/thread/PerChunkThreadProvider.java | 4 ++++ .../minestom/server/thread/PerInstanceThreadProvider.java | 4 ++++ src/main/java/net/minestom/server/thread/ThreadProvider.java | 4 ++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minestom/server/UpdateManager.java b/src/main/java/net/minestom/server/UpdateManager.java index a93c41e07..02320e746 100644 --- a/src/main/java/net/minestom/server/UpdateManager.java +++ b/src/main/java/net/minestom/server/UpdateManager.java @@ -8,7 +8,6 @@ import net.minestom.server.lock.Acquisition; import net.minestom.server.monitoring.TickMonitor; import net.minestom.server.network.ConnectionManager; import net.minestom.server.network.player.NettyPlayerConnection; -import net.minestom.server.thread.PerChunkThreadProvider; import net.minestom.server.thread.PerInstanceThreadProvider; import net.minestom.server.thread.ThreadProvider; import net.minestom.server.utils.async.AsyncUtils; @@ -40,8 +39,8 @@ public final class UpdateManager { { // DEFAULT THREAD PROVIDER - threadProvider = new PerInstanceThreadProvider(4); - //threadProvider = new PerChunkThreadProvider(4); + threadProvider = new PerInstanceThreadProvider(); + //threadProvider = new PerChunkThreadProvider(); } /** diff --git a/src/main/java/net/minestom/server/thread/PerChunkThreadProvider.java b/src/main/java/net/minestom/server/thread/PerChunkThreadProvider.java index 4025cefad..2365e42a6 100644 --- a/src/main/java/net/minestom/server/thread/PerChunkThreadProvider.java +++ b/src/main/java/net/minestom/server/thread/PerChunkThreadProvider.java @@ -12,6 +12,10 @@ public class PerChunkThreadProvider extends ThreadProvider { super(threadCount); } + public PerChunkThreadProvider() { + super(); + } + @Override public long findThread(@NotNull Chunk chunk) { return chunk.hashCode(); diff --git a/src/main/java/net/minestom/server/thread/PerInstanceThreadProvider.java b/src/main/java/net/minestom/server/thread/PerInstanceThreadProvider.java index 02903316d..ea0b3755a 100644 --- a/src/main/java/net/minestom/server/thread/PerInstanceThreadProvider.java +++ b/src/main/java/net/minestom/server/thread/PerInstanceThreadProvider.java @@ -13,6 +13,10 @@ public class PerInstanceThreadProvider extends ThreadProvider { super(threadCount); } + public PerInstanceThreadProvider() { + super(); + } + @Override public long findThread(@NotNull Chunk chunk) { return chunk.getInstance().hashCode(); diff --git a/src/main/java/net/minestom/server/thread/ThreadProvider.java b/src/main/java/net/minestom/server/thread/ThreadProvider.java index e0c64aa69..3e9bf6115 100644 --- a/src/main/java/net/minestom/server/thread/ThreadProvider.java +++ b/src/main/java/net/minestom/server/thread/ThreadProvider.java @@ -51,6 +51,10 @@ public abstract class ThreadProvider { } } + public ThreadProvider() { + this(Runtime.getRuntime().availableProcessors()); + } + public synchronized void onInstanceCreate(@NotNull Instance instance) { instance.getChunks().forEach(this::addChunk); }