Utilize multiple threads for Bedrock networking if possible

This commit is contained in:
Camotoy 2021-09-08 13:59:32 -04:00
parent 52ad5c37ee
commit 6dd4629fcd
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F

View file

@ -34,6 +34,8 @@ import com.nukkitx.network.util.EventLoops;
import com.nukkitx.protocol.bedrock.BedrockServer; import com.nukkitx.protocol.bedrock.BedrockServer;
import io.netty.channel.epoll.Epoll; import io.netty.channel.epoll.Epoll;
import io.netty.channel.kqueue.KQueue; import io.netty.channel.kqueue.KQueue;
import io.netty.util.NettyRuntime;
import io.netty.util.internal.SystemPropertyUtil;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.geysermc.common.PlatformType; import org.geysermc.common.PlatformType;
@ -233,10 +235,16 @@ public class GeyserConnector {
RakNetConstants.MAXIMUM_MTU_SIZE = (short) config.getMtu(); RakNetConstants.MAXIMUM_MTU_SIZE = (short) config.getMtu();
logger.debug("Setting MTU to " + config.getMtu()); logger.debug("Setting MTU to " + config.getMtu());
Integer bedrockThreadCount = Integer.getInteger("Geyser.BedrockNetworkThreads");
if (bedrockThreadCount == null) {
// Copy the code from Netty's default thread count fallback
bedrockThreadCount = Math.max(1, SystemPropertyUtil.getInt("io.netty.eventLoopThreads", NettyRuntime.availableProcessors() * 2));
}
boolean enableProxyProtocol = config.getBedrock().isEnableProxyProtocol(); boolean enableProxyProtocol = config.getBedrock().isEnableProxyProtocol();
bedrockServer = new BedrockServer( bedrockServer = new BedrockServer(
new InetSocketAddress(config.getBedrock().getAddress(), config.getBedrock().getPort()), new InetSocketAddress(config.getBedrock().getAddress(), config.getBedrock().getPort()),
1, bedrockThreadCount,
EventLoops.commonGroup(), EventLoops.commonGroup(),
enableProxyProtocol enableProxyProtocol
); );