Thread count should depend on the processor count

This commit is contained in:
TheMode 2021-04-21 17:14:40 +02:00
parent 15b116a770
commit dba368d16f
4 changed files with 14 additions and 3 deletions

View File

@ -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();
}
/**

View File

@ -12,6 +12,10 @@ public class PerChunkThreadProvider extends ThreadProvider {
super(threadCount);
}
public PerChunkThreadProvider() {
super();
}
@Override
public long findThread(@NotNull Chunk chunk) {
return chunk.hashCode();

View File

@ -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();

View File

@ -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);
}