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

Allow config of IO and acceptor threads in proxy #14054

Merged
merged 2 commits into from
Jan 30, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,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;

@Deprecated
@FieldContext(
category = CATEGORY_PLUGIN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ public class ProxyService implements Closeable {

private final ScheduledExecutorService statsExecutor;

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous default numThreads is Runtime.getRuntime().availableProcessors(), but the current default numThreads is Runtime.getRuntime().availableProcessors(). It has break the default behavior. Do we need to keep the default value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should move to the same default as the broker... primarily because I don't think having a single IO thread is generally something we want to do.

false, workersThreadFactory);
this.authenticationService = authenticationService;

// Initialize the message protocol handlers
Expand Down Expand Up @@ -276,7 +276,7 @@ private void startProxyExtension(String extensionName,
EventLoopUtil.enableTriggeredMode(bootstrap);
DefaultThreadFactory defaultThreadFactory = new DefaultThreadFactory("pulsar-ext-" + extensionName);
EventLoopGroup dedicatedWorkerGroup =
EventLoopUtil.newEventLoopGroup(numThreads, false, defaultThreadFactory);
EventLoopUtil.newEventLoopGroup(proxyConfig.getNumIOThreads(), false, defaultThreadFactory);
extensionsWorkerGroups.add(dedicatedWorkerGroup);
bootstrap.channel(EventLoopUtil.getServerSocketChannelClass(dedicatedWorkerGroup));
bootstrap.group(this.acceptorGroup, dedicatedWorkerGroup);
Expand Down