You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by eo...@apache.org on 2022/08/25 06:44:38 UTC

[bookkeeper] branch master updated: Make netty acceptor threadPool size configurable (#3153)

This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new f1b2256f9f Make netty acceptor threadPool size configurable (#3153)
f1b2256f9f is described below

commit f1b2256f9f251e6c9ddc4a6a728aba07a504b848
Author: grayson <91...@qq.com>
AuthorDate: Thu Aug 25 14:44:32 2022 +0800

    Make netty acceptor threadPool size configurable (#3153)
---
 .../org/apache/bookkeeper/conf/ServerConfiguration.java | 11 +++++++++++
 .../org/apache/bookkeeper/proto/BookieNettyServer.java  | 17 +++++++++++++++--
 .../java/org/apache/bookkeeper/util/EventLoopUtil.java  |  4 ++++
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java
index eebda93559..8044c34c52 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java
@@ -177,6 +177,8 @@ public class ServerConfiguration extends AbstractConfiguration<ServerConfigurati
     protected static final String SERVER_SOCK_LINGER = "serverTcpLinger";
     protected static final String SERVER_WRITEBUFFER_LOW_WATER_MARK = "serverWriteBufferLowWaterMark";
     protected static final String SERVER_WRITEBUFFER_HIGH_WATER_MARK = "serverWriteBufferHighWaterMark";
+
+    protected static final String SERVER_NUM_ACCEPTOR_THREADS = "serverNumAcceptorThreads";
     protected static final String SERVER_NUM_IO_THREADS = "serverNumIOThreads";
 
     // Zookeeper Parameters
@@ -1494,6 +1496,15 @@ public class ServerConfiguration extends AbstractConfiguration<ServerConfigurati
         return getInt(SERVER_NUM_IO_THREADS, 2 * Runtime.getRuntime().availableProcessors());
     }
 
+    /**
+     * Get the number of Acceptor threads.
+     *
+     * @return the number of Acceptor threads
+     */
+    public int getServerNumAcceptorThreads() {
+        return getInt(SERVER_NUM_ACCEPTOR_THREADS, 1);
+    }
+
     /**
      * Set the number of IO threads.
      *
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieNettyServer.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieNettyServer.java
index b301bd91ba..1d77283623 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieNettyServer.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieNettyServer.java
@@ -94,6 +94,7 @@ class BookieNettyServer {
     final int maxFrameSize;
     final ServerConfiguration conf;
     final EventLoopGroup eventLoopGroup;
+    final EventLoopGroup acceptorGroup;
     final EventLoopGroup jvmEventLoopGroup;
     RequestProcessor requestProcessor;
     final AtomicBoolean isRunning = new AtomicBoolean(false);
@@ -119,10 +120,14 @@ class BookieNettyServer {
         this.authProviderFactory = AuthProviderFactoryFactory.newBookieAuthProviderFactory(conf);
 
         if (!conf.isDisableServerSocketBind()) {
-            this.eventLoopGroup = EventLoopUtil.getServerEventLoopGroup(conf, new DefaultThreadFactory("bookie-io"));
+            this.eventLoopGroup = EventLoopUtil.getServerEventLoopGroup(conf,
+                    new DefaultThreadFactory("bookie-io"));
+            this.acceptorGroup = EventLoopUtil.getServerAcceptorGroup(conf,
+                    new DefaultThreadFactory("bookie-acceptor"));
             allChannels = new CleanupChannelGroup(eventLoopGroup);
         } else {
             this.eventLoopGroup = null;
+            this.acceptorGroup = null;
         }
 
         if (conf.isEnableLocalTransport()) {
@@ -302,7 +307,7 @@ class BookieNettyServer {
             ServerBootstrap bootstrap = new ServerBootstrap();
             bootstrap.option(ChannelOption.ALLOCATOR, allocator);
             bootstrap.childOption(ChannelOption.ALLOCATOR, allocator);
-            bootstrap.group(eventLoopGroup, eventLoopGroup);
+            bootstrap.group(acceptorGroup, eventLoopGroup);
             bootstrap.childOption(ChannelOption.TCP_NODELAY, conf.getServerTcpNoDelay());
             bootstrap.childOption(ChannelOption.SO_LINGER, conf.getServerSockLinger());
             bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR,
@@ -438,6 +443,14 @@ class BookieNettyServer {
 
         allChannels.close().awaitUninterruptibly();
 
+        if (acceptorGroup != null) {
+            try {
+                acceptorGroup.shutdownGracefully(0, 10, TimeUnit.MILLISECONDS).await();
+            } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+            }
+        }
+
         if (eventLoopGroup != null) {
             try {
                 eventLoopGroup.shutdownGracefully(0, 10, TimeUnit.MILLISECONDS).await();
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/EventLoopUtil.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/EventLoopUtil.java
index 83880be540..e6679d21f2 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/EventLoopUtil.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/EventLoopUtil.java
@@ -44,6 +44,10 @@ public class EventLoopUtil {
         return getEventLoopGroup(threadFactory, conf.getServerNumIOThreads(), conf.isBusyWaitEnabled());
     }
 
+    public static EventLoopGroup getServerAcceptorGroup(ServerConfiguration conf, ThreadFactory threadFactory) {
+        return getEventLoopGroup(threadFactory, conf.getServerNumAcceptorThreads(), false);
+    }
+
     private static EventLoopGroup getEventLoopGroup(ThreadFactory threadFactory,
             int numThreads, boolean enableBusyWait) {
         if (!SystemUtils.IS_OS_LINUX) {