9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-23 08:49:18 +00:00

configurable threads for async chunk sending

This commit is contained in:
NONPLAYT
2025-08-27 23:18:57 +03:00
parent 58d1a1be1b
commit c66fe68490
2 changed files with 10 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
package org.bxteam.divinemc.async;
import org.bxteam.divinemc.config.DivineConfig;
import org.bxteam.divinemc.util.NamedAgnosticThreadFactory;
import java.util.concurrent.ExecutorService;
@@ -9,7 +10,7 @@ import java.util.concurrent.TimeUnit;
public class AsyncChunkSend {
public static final ExecutorService POOL = new ThreadPoolExecutor(
1, 1, 0L, TimeUnit.MILLISECONDS,
1, DivineConfig.AsyncCategory.asyncChunkSendingMaxThreads, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(),
new NamedAgnosticThreadFactory<>("Async Chunk Sending", AsyncChunkSendThread::new, Thread.NORM_PRIORITY),
new ThreadPoolExecutor.CallerRunsPolicy()

View File

@@ -222,6 +222,7 @@ public class DivineConfig {
// Async chunk sending settings
public static boolean asyncChunkSendingEnabled = true;
public static int asyncChunkSendingMaxThreads = 1;
// Async mob spawning settings
public static boolean enableAsyncSpawning = true;
@@ -338,6 +339,13 @@ public class DivineConfig {
private static void asyncChunkSending() {
asyncChunkSendingEnabled = getBoolean(ConfigCategory.ASYNC.key("chunk-sending.enable"), asyncChunkSendingEnabled,
"Makes chunk sending asynchronous, which can significantly reduce main thread load when many players are loading chunks.");
asyncChunkSendingMaxThreads = getInt(ConfigCategory.ASYNC.key("chunk-sending.max-threads"), asyncChunkSendingMaxThreads);
if (asyncChunkSendingMaxThreads < 0) {
asyncChunkSendingMaxThreads = Math.max(Runtime.getRuntime().availableProcessors() + asyncChunkSendingMaxThreads, 1);
} else if (asyncChunkSendingMaxThreads == 0) {
asyncChunkSendingMaxThreads = Math.max(Runtime.getRuntime().availableProcessors() / 4, 1);
}
}
private static void asyncMobSpawning() {