Skip to content

Commit

Permalink
Allow config of IO and acceptor threads in proxy (apache#14054)
Browse files Browse the repository at this point in the history
* Allow config of IO and acceptor threads in proxy

Previously, the Pulasr Proxy did not allow configuration of the number
of IO threads and acceptor threads in the proxy.

These options can be very important to tune, as is tuneable in the
broker, so this change simply matches the brokers perspective.

Also, we increase the default number of IO threads to 2x number of
processors instead of 1x, as in a single CPU config, it still makes
sense to have 2 threads, at least for now, where some blocking
operatings can happen (such as authn/authz plugins)

* fix checkstyle

(cherry picked from commit f455418)
  • Loading branch information
addisonj authored and lhotari committed Apr 20, 2022
1 parent 4dbe72e commit 9feabea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Expand Up @@ -534,6 +534,20 @@ public class ProxyConfiguration implements PulsarConfiguration {
)
private int httpNumThreads = Math.max(8, 2 * Runtime.getRuntime().availableProcessors());

@FieldContext(
category = CATEGORY_SERVER,
doc = "Number of threads to use for Netty IO."
+ " Default is set to `2 * Runtime.getRuntime().availableProcessors()`"
)
private int numIOThreads = 2 * Runtime.getRuntime().availableProcessors();

@FieldContext(
category = CATEGORY_SERVER,
doc = "Number of threads to use for Netty Acceptor."
+ " Default is set to `1`"
)
private int numAcceptorThreads = 1;

@FieldContext(category = CATEGORY_SERVER, doc = "Max concurrent web requests")
private int maxConcurrentHttpRequests = 1024;

Expand Down
Expand Up @@ -99,8 +99,6 @@ public class ProxyService implements Closeable {

private final ScheduledExecutorService statsExecutor;

private static final int numThreads = Runtime.getRuntime().availableProcessors();

static final Gauge activeConnections = Gauge
.build("pulsar_proxy_active_connections", "Number of connections currently active in the proxy").create()
.register();
Expand Down Expand Up @@ -141,8 +139,10 @@ public ProxyService(ProxyConfiguration proxyConfig,
} else {
proxyLogLevel = 0;
}
this.acceptorGroup = EventLoopUtil.newEventLoopGroup(1, acceptorThreadFactory);
this.workerGroup = EventLoopUtil.newEventLoopGroup(numThreads, workersThreadFactory);
this.acceptorGroup = EventLoopUtil.newEventLoopGroup(proxyConfig.getNumAcceptorThreads(),
acceptorThreadFactory);
this.workerGroup = EventLoopUtil.newEventLoopGroup(proxyConfig.getNumIOThreads(),
workersThreadFactory);
this.authenticationService = authenticationService;

DnsNameResolverBuilder dnsNameResolverBuilder = new DnsNameResolverBuilder(workerGroup.next())
Expand Down

0 comments on commit 9feabea

Please sign in to comment.