This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 6e7bc6be51ed94deb022209310a6a662880c1813 Author: Benoit TELLIER <btell...@linagora.com> AuthorDate: Mon Mar 18 16:56:07 2024 +0100 [ENHANCEMENT] IMAP configuration for netty high/low write buffer watermarks --- .../apache/james/protocols/netty/AbstractAsyncServer.java | 6 ++++++ .../docs/modules/ROOT/pages/configure/imap.adoc | 6 ++++++ .../java/org/apache/james/imapserver/netty/IMAPServer.java | 1 + .../lib/netty/AbstractConfigurableAsyncServer.java | 13 +++++++++++++ src/site/xdoc/server/config-imap4.xml | 4 ++++ 5 files changed, 30 insertions(+) diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractAsyncServer.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractAsyncServer.java index 1a7c09c76f..c364e80498 100644 --- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractAsyncServer.java +++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractAsyncServer.java @@ -34,6 +34,7 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; +import io.netty.channel.WriteBufferWaterMark; import io.netty.channel.epoll.EpollEventLoopGroup; import io.netty.channel.epoll.EpollServerSocketChannel; import io.netty.channel.group.ChannelGroup; @@ -73,6 +74,7 @@ public abstract class AbstractAsyncServer implements ProtocolServer { private boolean gracefulShutdown = true; private boolean useEpoll = false; + protected WriteBufferWaterMark writeBufferWaterMark = WriteBufferWaterMark.DEFAULT; public synchronized void setListenAddresses(InetSocketAddress... addresses) { if (started) { @@ -89,6 +91,10 @@ public abstract class AbstractAsyncServer implements ProtocolServer { this.useEpoll = useEpoll; } + public void setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark) { + this.writeBufferWaterMark = writeBufferWaterMark; + } + /** * Set the IO-worker thread count to use. * diff --git a/server/apps/distributed-app/docs/modules/ROOT/pages/configure/imap.adoc b/server/apps/distributed-app/docs/modules/ROOT/pages/configure/imap.adoc index 72352f0fa2..862400ab92 100644 --- a/server/apps/distributed-app/docs/modules/ROOT/pages/configure/imap.adoc +++ b/server/apps/distributed-app/docs/modules/ROOT/pages/configure/imap.adoc @@ -139,6 +139,12 @@ Optional integer, defaults to 2 times the count of CPUs. | gracefulShutdown | true or false - If true attempts a graceful shutdown, which is safer but can take time. Defaults to true. + +| highWriteBufferWaterMark +| Netty's write buffer high watermark configuration. Unit supported: none, K, M. Netty defaults applied. + +| lowWriteBufferWaterMark +| Netty's write buffer low watermark configuration. Unit supported: none, K, M. Netty defaults applied. |=== == OIDC setup diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java index f4fa0c5412..a80fb2e882 100644 --- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java +++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java @@ -243,6 +243,7 @@ public class IMAPServer extends AbstractConfigurableAsyncServer implements ImapC @Override public void initChannel(Channel channel) { ChannelPipeline pipeline = channel.pipeline(); + channel.config().setWriteBufferWaterMark(writeBufferWaterMark); pipeline.addLast(TIMEOUT_HANDLER, new ImapIdleStateHandler(timeout)); connectionLimitUpstreamHandler.ifPresent(handler -> pipeline.addLast(HandlerConstants.CONNECTION_LIMIT_HANDLER, handler)); diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java index 7f2f3338cd..f66c7d9da0 100644 --- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java +++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java @@ -48,6 +48,7 @@ import org.apache.james.protocols.netty.AbstractChannelPipelineFactory; import org.apache.james.protocols.netty.AbstractSSLAwareChannelPipelineFactory; import org.apache.james.protocols.netty.ChannelHandlerFactory; import org.apache.james.protocols.netty.Encryption; +import org.apache.james.util.Size; import org.apache.james.util.concurrent.NamedThreadFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,6 +56,7 @@ import org.slf4j.LoggerFactory; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelOption; +import io.netty.channel.WriteBufferWaterMark; import io.netty.util.concurrent.DefaultEventExecutorGroup; import io.netty.util.concurrent.EventExecutorGroup; @@ -226,6 +228,17 @@ public abstract class AbstractConfigurableAsyncServer Optional.ofNullable(config.getBoolean("gracefulShutdown", null)).ifPresent(this::setGracefulShutdown); Optional.ofNullable(config.getBoolean("useEpoll", null)).ifPresent(this::setUseEpoll); + Optional<Size> highWaterMark = Optional.ofNullable(config.getString("highWriteBufferWaterMark", null)).map(Size::parse); + Optional<Size> lowWaterMark = Optional.ofNullable(config.getString("lowWriteBufferWaterMark", null)).map(Size::parse); + + if (highWaterMark.isPresent() || lowWaterMark.isPresent()) { + setWriteBufferWaterMark(new WriteBufferWaterMark( + (int) lowWaterMark.or(() -> highWaterMark).get().asBytes(), + (int) highWaterMark.or(() -> lowWaterMark).get().asBytes())); + } + + Optional.ofNullable(config.getBoolean("useEpoll", null)).ifPresent(this::setUseEpoll); + proxyRequired = config.getBoolean(PROXY_REQUIRED, false); doConfigure(config); diff --git a/src/site/xdoc/server/config-imap4.xml b/src/site/xdoc/server/config-imap4.xml index 2f541a0c0b..1b10bc1255 100644 --- a/src/site/xdoc/server/config-imap4.xml +++ b/src/site/xdoc/server/config-imap4.xml @@ -127,6 +127,10 @@ <dt><strong>gracefulShutdown</strong></dt> <dd>true or false - If true attemps a graceful shutdown, which is safer but can take time. Defaults to true.</dd> + <dt><strong>highWriteBufferWaterMark</strong></dt> + <dd>Netty's write buffer high watermark configuration. Unit supported: none, K, M. Netty defaults applied.</dd> + <dt><strong>lowWriteBufferWaterMark</strong></dt> + <dd>Netty's write buffer low watermark configuration. Unit supported: none, K, M. Netty defaults applied.</dd> <dt><strong>ignoreIDLEUponProcessing</strong></dt> <dd>true or false - Allow disabling the heartbeat handler. Defaults to true.</dd> --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For additional commands, e-mail: notifications-h...@james.apache.org