9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-29 20:09:17 +00:00

update async chunk send (#307)

* cleanup

* Async Chunk Send

---------

Co-authored-by: Taiyou06 <kaandindar21@gmail.com>
This commit is contained in:
hayanesuru
2025-05-07 02:28:16 +09:00
committed by GitHub
parent 974ede5f87
commit a53ddc7f8c
7 changed files with 230 additions and 117 deletions

View File

@@ -1,9 +0,0 @@
package org.dreeam.leaf.async;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class AsyncChunkSending {
public static final Logger LOGGER = LogManager.getLogger(AsyncChunkSending.class.getSimpleName());
}

View File

@@ -0,0 +1,25 @@
package org.dreeam.leaf.async.chunk;
import net.minecraft.Util;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class AsyncChunkSend {
public static final ExecutorService POOL = new ThreadPoolExecutor(
1, 1, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(),
new com.google.common.util.concurrent.ThreadFactoryBuilder()
.setPriority(Thread.NORM_PRIORITY - 2)
.setNameFormat("Leaf Async Chunk Send Thread")
.setUncaughtExceptionHandler(Util::onThreadException)
.setThreadFactory(AsyncChunkSendThread::new)
.build(),
new ThreadPoolExecutor.DiscardPolicy()
);
public static final Logger LOGGER = LogManager.getLogger("Leaf Async Chunk Send");
}

View File

@@ -0,0 +1,7 @@
package org.dreeam.leaf.async.chunk;
public class AsyncChunkSendThread extends Thread {
protected AsyncChunkSendThread(Runnable task) {
super(task);
}
}

View File

@@ -10,6 +10,7 @@ public class AsyncChunkSend extends ConfigModules {
}
public static boolean enabled = false;
private static boolean asyncChunkSendInitialized;
@Override
public void onLoaded() {
@@ -20,6 +21,12 @@ public class AsyncChunkSend extends ConfigModules {
使区块数据包准备和发送异步化以提高服务器性能.
当许多玩家同时加载区块时, 这可以显著减少主线程负载.""");
if (asyncChunkSendInitialized) {
config.getConfigSection(getBasePath());
return;
}
asyncChunkSendInitialized = true;
enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
}
}