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

Async playerPacket sending (#245)

* async player packet sending

* small cleanup

* eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

* holy shit this is fast

* some cleanup

* change .size to O(1)

* rewrite starts (i need to do this OMEGA SAFE)

* rebuilt

* rebase

* Rewritten AsyncPacketSending
This commit is contained in:
Taiyou
2025-03-25 08:20:49 +01:00
committed by GitHub
parent a7515a3918
commit cbcc54726a
28 changed files with 372 additions and 119 deletions

View File

@@ -177,4 +177,19 @@ public class LeafGlobalConfig {
public String pickStringRegionBased(String en, String cn) {
return isCN ? cn : en;
}
public long getLong(String path, long def, String comment) {
configFile.addDefault(path, def, comment);
return configFile.getLong(path, def);
}
public long getLong(String path, long def) {
configFile.addDefault(path, def);
return configFile.getLong(path, def);
}
public Long getLong(String path) {
String value = configFile.getString(path, null);
return value == null ? null : Long.parseLong(value);
}
}

View File

@@ -0,0 +1,50 @@
package org.dreeam.leaf.config.modules.async;
import org.dreeam.leaf.config.ConfigModules;
import org.dreeam.leaf.config.EnumConfigCategory;
import org.dreeam.leaf.config.annotations.Experimental;
public class AsyncPacketSending extends ConfigModules {
public String getBasePath() {
return EnumConfigCategory.ASYNC.getBaseKeyName() + ".async-packet-sending";
}
@Experimental
public static boolean enabled = false;
public static int threadPoolSize = 4;
public static int queueCapacity = 4096;
public static boolean prioritizeMovementPackets = true;
public static boolean prioritizeChatPackets = true;
public static boolean spinWaitForReadyPackets = true;
public static long spinTimeNanos = 1000; // 1 microsecond
public static boolean batchProcessing = true;
public static int batchSize = 128;
private static boolean asyncPacketSendingInitialized;
@Override
public void onLoaded() {
config.addCommentRegionBased(getBasePath(), """
**Experimental feature**
This moves packet sending operations to background threads, reducing main thread load.
Can significantly improve performance on high-player-count servers.""",
"""
这将数据包发送操作移至后台线程,减少主线程负载。
在高玩家数量的服务器上可以显著提高性能。""");
if (!asyncPacketSendingInitialized) {
asyncPacketSendingInitialized = true;
enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
threadPoolSize = config.getInt(getBasePath() + ".thread-pool-size", threadPoolSize);
queueCapacity = config.getInt(getBasePath() + ".queue-capacity", queueCapacity);
prioritizeMovementPackets = config.getBoolean(getBasePath() + ".prioritize-movement-packets", prioritizeMovementPackets);
prioritizeChatPackets = config.getBoolean(getBasePath() + ".prioritize-chat-packets", prioritizeChatPackets);
spinWaitForReadyPackets = config.getBoolean(getBasePath() + ".spin-wait-for-ready-packets", spinWaitForReadyPackets);
spinTimeNanos = config.getLong(getBasePath() + ".spin-time-nanos", spinTimeNanos);
batchProcessing = config.getBoolean(getBasePath() + ".batch-processing", batchProcessing);
batchSize = config.getInt(getBasePath() + ".batch-size", batchSize);
}
}
}