Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the number of Netty worker threads number configurable #468

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions broker/src/main/java/io/moquette/BrokerConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public final class BrokerConstants {
public static final String NETTY_EPOLL_PROPERTY_NAME = "netty.epoll";
public static final String NETTY_MAX_BYTES_PROPERTY_NAME = "netty.mqtt.message_size";
public static final int DEFAULT_NETTY_MAX_BYTES_IN_MESSAGE = 8092;
public static final String NETTY_WORKER_THREADS = "netty.worker_threads";
public static final String IMMEDIATE_BUFFER_FLUSH_PROPERTY_NAME = "immediate_buffer_flush";
public static final String METRICS_ENABLE_PROPERTY_NAME = "use_metrics";
public static final String METRICS_LIBRATO_EMAIL_PROPERTY_NAME = "metrics.librato.email";
Expand Down
15 changes: 13 additions & 2 deletions broker/src/main/java/io/moquette/broker/NewNettyAcceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,28 @@ public void initialize(NewNettyMQTTHandler mqttHandler, IConfig props, ISslConte
nettyChannelTimeoutSeconds = props.intProp(BrokerConstants.NETTY_CHANNEL_TIMEOUT_SECONDS_PROPERTY_NAME, 10);
maxBytesInMessage = props.intProp(BrokerConstants.NETTY_MAX_BYTES_PROPERTY_NAME,
BrokerConstants.DEFAULT_NETTY_MAX_BYTES_IN_MESSAGE);
int nettyWorkerThreads = props.intProp(BrokerConstants.NETTY_WORKER_THREADS, 0);

boolean epoll = props.boolProp(BrokerConstants.NETTY_EPOLL_PROPERTY_NAME, false);
if (epoll) {
LOG.info("Netty is using Epoll");
bossGroup = new EpollEventLoopGroup();
workerGroup = new EpollEventLoopGroup();
if (nettyWorkerThreads == 0) {
workerGroup = new EpollEventLoopGroup();
}
else {
workerGroup = new EpollEventLoopGroup(nettyWorkerThreads);
}
channelClass = EpollServerSocketChannel.class;
} else {
LOG.info("Netty is using NIO");
bossGroup = new NioEventLoopGroup();
workerGroup = new NioEventLoopGroup();
if (nettyWorkerThreads == 0) {
workerGroup = new NioEventLoopGroup();
}
else {
workerGroup = new NioEventLoopGroup(nettyWorkerThreads);
}
channelClass = NioServerSocketChannel.class;
}

Expand Down