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:
@@ -1,5 +1,6 @@
|
|||||||
package org.bxteam.divinemc.async;
|
package org.bxteam.divinemc.async;
|
||||||
|
|
||||||
|
import org.bxteam.divinemc.config.DivineConfig;
|
||||||
import org.bxteam.divinemc.util.NamedAgnosticThreadFactory;
|
import org.bxteam.divinemc.util.NamedAgnosticThreadFactory;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
@@ -9,7 +10,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
public class AsyncChunkSend {
|
public class AsyncChunkSend {
|
||||||
public static final ExecutorService POOL = new ThreadPoolExecutor(
|
public static final ExecutorService POOL = new ThreadPoolExecutor(
|
||||||
1, 1, 0L, TimeUnit.MILLISECONDS,
|
1, DivineConfig.AsyncCategory.asyncChunkSendingMaxThreads, 0L, TimeUnit.MILLISECONDS,
|
||||||
new LinkedBlockingQueue<>(),
|
new LinkedBlockingQueue<>(),
|
||||||
new NamedAgnosticThreadFactory<>("Async Chunk Sending", AsyncChunkSendThread::new, Thread.NORM_PRIORITY),
|
new NamedAgnosticThreadFactory<>("Async Chunk Sending", AsyncChunkSendThread::new, Thread.NORM_PRIORITY),
|
||||||
new ThreadPoolExecutor.CallerRunsPolicy()
|
new ThreadPoolExecutor.CallerRunsPolicy()
|
||||||
|
|||||||
@@ -222,6 +222,7 @@ public class DivineConfig {
|
|||||||
|
|
||||||
// Async chunk sending settings
|
// Async chunk sending settings
|
||||||
public static boolean asyncChunkSendingEnabled = true;
|
public static boolean asyncChunkSendingEnabled = true;
|
||||||
|
public static int asyncChunkSendingMaxThreads = 1;
|
||||||
|
|
||||||
// Async mob spawning settings
|
// Async mob spawning settings
|
||||||
public static boolean enableAsyncSpawning = true;
|
public static boolean enableAsyncSpawning = true;
|
||||||
@@ -338,6 +339,13 @@ public class DivineConfig {
|
|||||||
private static void asyncChunkSending() {
|
private static void asyncChunkSending() {
|
||||||
asyncChunkSendingEnabled = getBoolean(ConfigCategory.ASYNC.key("chunk-sending.enable"), asyncChunkSendingEnabled,
|
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.");
|
"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() {
|
private static void asyncMobSpawning() {
|
||||||
|
|||||||
Reference in New Issue
Block a user