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 e4fb4c6984824e6e4bd581642ff146198e8f28e1
Author: Benoit TELLIER <btell...@linagora.com>
AuthorDate: Mon Mar 18 15:26:01 2024 +0100

    [ENHANCEMENT] Allow James to use native Netty Epoll
---
 pom.xml                                            |  5 +++++
 protocols/netty/pom.xml                            |  4 ++++
 .../james/protocols/netty/AbstractAsyncServer.java | 22 +++++++++++++++++-----
 .../docs/modules/ROOT/pages/configure/imap.adoc    |  6 ++++++
 .../docs/modules/ROOT/pages/configure/pop3.adoc    |  6 ++++++
 .../docs/modules/ROOT/pages/configure/smtp.adoc    |  6 ++++++
 .../lib/netty/AbstractConfigurableAsyncServer.java |  1 +
 src/site/xdoc/server/config-imap4.xml              |  7 +++++++
 src/site/xdoc/server/config-pop3.xml               |  7 +++++++
 src/site/xdoc/server/config-smtp-lmtp.xml          |  6 ++++++
 10 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/pom.xml b/pom.xml
index f6f64705da..7f00a56b60 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2462,6 +2462,11 @@
                 <artifactId>netty-transport</artifactId>
                 <version>${netty.version}</version>
             </dependency>
+            <dependency>
+                <groupId>io.netty</groupId>
+                <artifactId>netty-transport-native-epoll</artifactId>
+                <version>${netty.version}</version>
+            </dependency>
             <dependency>
                 <groupId>io.projectreactor</groupId>
                 <artifactId>reactor-bom</artifactId>
diff --git a/protocols/netty/pom.xml b/protocols/netty/pom.xml
index 34a036950b..1e821b95a1 100644
--- a/protocols/netty/pom.xml
+++ b/protocols/netty/pom.xml
@@ -58,6 +58,10 @@
             <groupId>io.netty</groupId>
             <artifactId>netty-handler</artifactId>
         </dependency>
+        <dependency>
+            <groupId>io.netty</groupId>
+            <artifactId>netty-transport-native-epoll</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-core</artifactId>
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 93036043a4..1a7c09c76f 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,8 @@ import io.netty.channel.Channel;
 import io.netty.channel.ChannelInitializer;
 import io.netty.channel.ChannelOption;
 import io.netty.channel.EventLoopGroup;
+import io.netty.channel.epoll.EpollEventLoopGroup;
+import io.netty.channel.epoll.EpollServerSocketChannel;
 import io.netty.channel.group.ChannelGroup;
 import io.netty.channel.group.DefaultChannelGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
@@ -70,7 +72,8 @@ public abstract class AbstractAsyncServer implements 
ProtocolServer {
     protected String jmxName;
 
     private boolean gracefulShutdown = true;
-    
+    private boolean useEpoll = false;
+
     public synchronized void setListenAddresses(InetSocketAddress... 
addresses) {
         if (started) {
             throw new IllegalStateException("Can only be set when the server 
is not running");
@@ -82,6 +85,10 @@ public abstract class AbstractAsyncServer implements 
ProtocolServer {
         this.gracefulShutdown = gracefulShutdown;
     }
 
+    public void setUseEpoll(boolean useEpoll) {
+        this.useEpoll = useEpoll;
+    }
+
     /**
      * Set the IO-worker thread count to use.
      *
@@ -121,10 +128,15 @@ public abstract class AbstractAsyncServer implements 
ProtocolServer {
         }
 
         ServerBootstrap bootstrap = new ServerBootstrap();
-        bootstrap.channel(NioServerSocketChannel.class);
-
-        bossGroup = bossWorker.map(count -> new NioEventLoopGroup(count, 
NamedThreadFactory.withName(jmxName + "-boss")));
-        workerGroup = new NioEventLoopGroup(ioWorker, 
NamedThreadFactory.withName(jmxName + "-io"));
+        if (useEpoll) {
+            bootstrap.channel(EpollServerSocketChannel.class);
+            bossGroup = bossWorker.map(count -> new EpollEventLoopGroup(count, 
NamedThreadFactory.withName(jmxName + "-boss")));
+            workerGroup = new EpollEventLoopGroup(ioWorker, 
NamedThreadFactory.withName(jmxName + "-io"));
+        } else {
+            bootstrap.channel(NioServerSocketChannel.class);
+            bossGroup = bossWorker.map(count -> new NioEventLoopGroup(count, 
NamedThreadFactory.withName(jmxName + "-boss")));
+            workerGroup = new NioEventLoopGroup(ioWorker, 
NamedThreadFactory.withName(jmxName + "-io"));
+        }
 
         bossGroup.<Runnable>map(boss -> () -> bootstrap.group(boss, 
workerGroup))
             .orElse(() -> bootstrap.group(workerGroup))
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 f99b27ef74..72352f0fa2 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
@@ -133,6 +133,12 @@ Optional integer, defaults to 2 times the count of CPUs.
 
 | ignoreIDLEUponProcessing
 | true or false - Allow disabling the heartbeat handler. Defaults to true.
+
+| useEpoll
+| true or false - If true uses native EPOLL implementation for Netty otherwise 
uses NIO. Defaults to false.
+
+| gracefulShutdown
+| true or false - If true attempts a graceful shutdown, which is safer but can 
take time. Defaults to true.
 |===
 
 == OIDC setup
diff --git 
a/server/apps/distributed-app/docs/modules/ROOT/pages/configure/pop3.adoc 
b/server/apps/distributed-app/docs/modules/ROOT/pages/configure/pop3.adoc
index fdde5ebf39..ceef7b5da5 100644
--- a/server/apps/distributed-app/docs/modules/ROOT/pages/configure/pop3.adoc
+++ b/server/apps/distributed-app/docs/modules/ROOT/pages/configure/pop3.adoc
@@ -68,4 +68,10 @@ Optional integer, defaults to 2 times the count of CPUs.
 
 | maxExecutorCount
 | Set the maximum count of worker threads. Worker threads takes care of 
potentially blocking tasks like executing POP3 requests. Optional integer, 
defaults to 16.
+
+| useEpoll
+| true or false - If true uses native EPOLL implementation for Netty otherwise 
uses NIO. Defaults to false.
+
+| gracefulShutdown
+| true or false - If true attempts a graceful shutdown, which is safer but can 
take time. Defaults to true.
 |===
\ No newline at end of file
diff --git 
a/server/apps/distributed-app/docs/modules/ROOT/pages/configure/smtp.adoc 
b/server/apps/distributed-app/docs/modules/ROOT/pages/configure/smtp.adoc
index ddd6e31ee7..f967d99e4f 100644
--- a/server/apps/distributed-app/docs/modules/ROOT/pages/configure/smtp.adoc
+++ b/server/apps/distributed-app/docs/modules/ROOT/pages/configure/smtp.adoc
@@ -181,6 +181,12 @@ Optional integer, defaults to 2 times the count of CPUs.
 | Set the maximum count of worker threads. Worker threads takes care of 
potentially blocking tasks like executing SMTP commands.
 Optional integer, defaults to 16.
 
+| useEpoll
+| true or false - If true uses native EPOLL implementation for Netty otherwise 
uses NIO. Defaults to false.
+
+| gracefulShutdown
+| true or false - If true attempts a graceful shutdown, which is safer but can 
take time. Defaults to true.
+
 | disabledFeatures
 | Extended SMTP features to hide in EHLO responses.
 |===
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 6b30342e60..7f2f3338cd 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
@@ -224,6 +224,7 @@ public abstract class AbstractConfigurableAsyncServer
         sslConfig = SslConfig.parse(config);
 
         Optional.ofNullable(config.getBoolean("gracefulShutdown", 
null)).ifPresent(this::setGracefulShutdown);
+        Optional.ofNullable(config.getBoolean("useEpoll", 
null)).ifPresent(this::setUseEpoll);
 
         proxyRequired = config.getBoolean(PROXY_REQUIRED, false);
 
diff --git a/src/site/xdoc/server/config-imap4.xml 
b/src/site/xdoc/server/config-imap4.xml
index 8a1cbfb620..2f541a0c0b 100644
--- a/src/site/xdoc/server/config-imap4.xml
+++ b/src/site/xdoc/server/config-imap4.xml
@@ -121,6 +121,13 @@
           (split line by line). IO threads also take care of compression and 
SSL encryption. Their tasks are short-lived and non-blocking.
               Optional integer, defaults to 2 times the count of CPUs.</dd>
 
+
+          <dt><strong>useEpoll</strong></dt>
+          <dd>true or false - If true uses native EPOLL implementation for 
Netty otherwise uses NIO. Defaults to false.</dd>
+
+          <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>ignoreIDLEUponProcessing</strong></dt>
         <dd>true or false - Allow disabling the heartbeat handler. Defaults to 
true.</dd>
       </dl>
diff --git a/src/site/xdoc/server/config-pop3.xml 
b/src/site/xdoc/server/config-pop3.xml
index fd53a2ed7f..12eefe652a 100644
--- a/src/site/xdoc/server/config-pop3.xml
+++ b/src/site/xdoc/server/config-pop3.xml
@@ -82,6 +82,13 @@
         <dt><strong>maxExecutorCount</strong></dt>
         <dd>Set the maximum count of worker threads. Worker threads takes care 
of potentially blocking tasks like executing POP3 requests.
             Optional integer, defaults to 16.</dd>
+
+
+          <dt><strong>useEpoll</strong></dt>
+          <dd>true or false - If true uses native EPOLL implementation for 
Netty otherwise uses NIO. Defaults to false.</dd>
+
+          <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>
       </dl>
 
   </section>
diff --git a/src/site/xdoc/server/config-smtp-lmtp.xml 
b/src/site/xdoc/server/config-smtp-lmtp.xml
index a37677017a..cc64039696 100644
--- a/src/site/xdoc/server/config-smtp-lmtp.xml
+++ b/src/site/xdoc/server/config-smtp-lmtp.xml
@@ -182,6 +182,12 @@
       <dd>Set the maximum count of worker threads. Worker threads takes care 
of potentially blocking tasks like
           executing SMTP commands. Optional integer, defaults to 16.</dd>
 
+      <dt><strong>useEpoll</strong></dt>
+      <dd>true or false - If true uses native EPOLL implementation for Netty 
otherwise uses NIO. Defaults to false.</dd>
+
+      <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>disabledFeatures</strong></dt>
       <dd>Extended SMTP features to hide in EHLO responses.</dd>
     </dl>


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org
For additional commands, e-mail: notifications-h...@james.apache.org

Reply via email to