Multi-core event loop group

This commit is contained in:
Andrea Cavalli 2024-09-26 23:57:18 +02:00
parent e580f80384
commit 54a239d369

View File

@ -15,6 +15,7 @@ import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollServerDomainSocketChannel; import io.netty.channel.epoll.EpollServerDomainSocketChannel;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.util.NettyRuntime;
import it.cavallium.rockserver.core.client.RocksDBConnection; import it.cavallium.rockserver.core.client.RocksDBConnection;
import it.cavallium.rockserver.core.common.*; import it.cavallium.rockserver.core.common.*;
import it.cavallium.rockserver.core.common.ColumnHashType; import it.cavallium.rockserver.core.common.ColumnHashType;
@ -71,10 +72,11 @@ public class GrpcServer extends Server {
EventLoopGroup elg; EventLoopGroup elg;
Class<? extends ServerChannel> channelType; Class<? extends ServerChannel> channelType;
try { try {
elg = new EpollEventLoopGroup(Math.min(8, Runtime.getRuntime().availableProcessors())); elg = new EpollEventLoopGroup(Runtime.getRuntime().availableProcessors() * 2);
channelType = EpollServerDomainSocketChannel.class; channelType = EpollServerDomainSocketChannel.class;
} catch (UnsatisfiedLinkError ex) { } catch (UnsatisfiedLinkError ex) {
elg = new NioEventLoopGroup(); LOG.warn("Can't load Epoll event loop group, the server will be slower", ex);
elg = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors() * 2);
channelType = NioServerSocketChannel.class; channelType = NioServerSocketChannel.class;
} }
this.elg = elg; this.elg = elg;