From 8404135e42ed2d5c16ec3eb68df4b195d58c7fc7 Mon Sep 17 00:00:00 2001 From: Nanit Date: Sun, 29 Nov 2020 15:10:33 +0200 Subject: [PATCH] Added extra params in config for Netty --- .../limbo/configuration/LimboConfig.java | 20 +++++++++++++++++++ .../ru/nanit/limbo/server/LimboServer.java | 10 +++++----- src/main/resources/settings.yml | 11 +++++++++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java b/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java index d64daab..b1ec9c0 100644 --- a/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java +++ b/src/main/java/ru/nanit/limbo/configuration/LimboConfig.java @@ -30,6 +30,10 @@ public final class LimboConfig { private long readTimeout; private int debugLevel = 3; + private boolean useEpoll; + private int bossGroupSize; + private int workerGroupSize; + public LimboConfig(Path root){ this.root = root; } @@ -59,6 +63,10 @@ public final class LimboConfig { infoForwarding = conf.getNode("infoForwarding").getValue(InfoForwarding.class); readTimeout = conf.getNode("readTimeout").getLong(); debugLevel = conf.getNode("debugLevel").getInt(); + + useEpoll = conf.getNode("netty", "useEpoll").getBoolean(true); + bossGroupSize = conf.getNode("netty", "threads", "bossGroup").getInt(1); + workerGroupSize = conf.getNode("netty", "threads", "workerGroup").getInt(4); } public SocketAddress getAddress() { @@ -112,4 +120,16 @@ public final class LimboConfig { public BossBar getBossBar() { return bossBar; } + + public boolean isUseEpoll() { + return useEpoll; + } + + public int getBossGroupSize() { + return bossGroupSize; + } + + public int getWorkerGroupSize() { + return workerGroupSize; + } } diff --git a/src/main/java/ru/nanit/limbo/server/LimboServer.java b/src/main/java/ru/nanit/limbo/server/LimboServer.java index ca8c065..2c0cdb4 100644 --- a/src/main/java/ru/nanit/limbo/server/LimboServer.java +++ b/src/main/java/ru/nanit/limbo/server/LimboServer.java @@ -80,14 +80,14 @@ public final class LimboServer { private void startBootstrap(){ Class channelClass; - if (Epoll.isAvailable()){ - bossGroup = new EpollEventLoopGroup(1); - workerGroup = new EpollEventLoopGroup(4); + if (config.isUseEpoll() && Epoll.isAvailable()){ + bossGroup = new EpollEventLoopGroup(config.getBossGroupSize()); + workerGroup = new EpollEventLoopGroup(config.getWorkerGroupSize()); channelClass = EpollServerSocketChannel.class; Logger.debug("Using Epoll transport type"); } else { - bossGroup = new NioEventLoopGroup(1); - workerGroup = new NioEventLoopGroup(4); + bossGroup = new NioEventLoopGroup(config.getBossGroupSize()); + workerGroup = new NioEventLoopGroup(config.getWorkerGroupSize()); channelClass = NioServerSocketChannel.class; Logger.debug("Using Java NIO transport type"); } diff --git a/src/main/resources/settings.yml b/src/main/resources/settings.yml index c992ce1..6badb5f 100644 --- a/src/main/resources/settings.yml +++ b/src/main/resources/settings.yml @@ -64,4 +64,13 @@ readTimeout: 30000 # 1 - Display info and some debug # 2 - Display info and warnings # 3 - Display info, warnings, errors -debugLevel: 3 \ No newline at end of file +debugLevel: 3 + +# Warning! Do not touch params of this block, if you not completely sure what is this! +netty: + # Use Linux native transport type, if it possible + useEpoll: true + # EventLoopGroup threads count + threads: + bossGroup: 1 + workerGroup: 4 \ No newline at end of file