From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> Date: Sat, 22 Feb 2025 02:33:28 +0300 Subject: [PATCH] Add chunk worker algorithm diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java b/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java index 632920e04686d8a0fd0a60e87348be1fe7862a3c..27447481c6e6b526cda032aff54a5c87256c217d 100644 --- a/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java +++ b/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java @@ -3,6 +3,8 @@ package ca.spottedleaf.moonrise.common.util; import ca.spottedleaf.concurrentutil.executor.thread.PrioritisedThreadPool; import ca.spottedleaf.moonrise.common.PlatformHooks; import com.mojang.logging.LogUtils; +import org.bxteam.divinemc.DivineConfig; +import org.bxteam.divinemc.server.chunk.ChunkSystemAlgorithms; import org.slf4j.Logger; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -29,7 +31,7 @@ public final class MoonriseCommon { } } ); - public static final long WORKER_QUEUE_HOLD_TIME = (long)(20.0e6); // 20ms + public static final long WORKER_QUEUE_HOLD_TIME = (long)(2.0e6); // 2ms // DivineMC - Reduce from 20ms to 2ms public static final int CLIENT_DIVISION = 0; public static final PrioritisedThreadPool.ExecutorGroup RENDER_EXECUTOR_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(CLIENT_DIVISION, 0); public static final int SERVER_DIVISION = 1; @@ -38,26 +40,16 @@ public final class MoonriseCommon { public static final PrioritisedThreadPool.ExecutorGroup LOAD_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(SERVER_DIVISION, 0); public static void adjustWorkerThreads(final int configWorkerThreads, final int configIoThreads) { - int defaultWorkerThreads = Runtime.getRuntime().availableProcessors() / 2; - if (defaultWorkerThreads <= 4) { - defaultWorkerThreads = defaultWorkerThreads <= 3 ? 1 : 2; - } else { - defaultWorkerThreads = defaultWorkerThreads / 2; - } - defaultWorkerThreads = Integer.getInteger(PlatformHooks.get().getBrand() + ".WorkerThreadCount", Integer.valueOf(defaultWorkerThreads)); - - int workerThreads = configWorkerThreads; - - if (workerThreads <= 0) { - workerThreads = defaultWorkerThreads; - } - - final int ioThreads = Math.max(1, configIoThreads); + // DivineMC start - Add chunk worker algorithm + ChunkSystemAlgorithms algorithm = DivineConfig.chunkWorkerAlgorithm; + int workerThreads = algorithm.evalWorkers(configWorkerThreads, configIoThreads); + int ioThreads = algorithm.evalIO(configWorkerThreads, configIoThreads); WORKER_POOL.adjustThreadCount(workerThreads); IO_POOL.adjustThreadCount(ioThreads); - LOGGER.info(PlatformHooks.get().getBrand() + " is using " + workerThreads + " worker threads, " + ioThreads + " I/O threads"); + LOGGER.info("ChunkSystem using '{}' algorithm, {} worker threads, {} I/O threads", algorithm.asDebugString(), workerThreads, ioThreads); + // DivineMC end - Add chunk worker algorithm } public static final PrioritisedThreadPool IO_POOL = new PrioritisedThreadPool(