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

Scale the system executor provider with the number of pull channels #4592

Merged
merged 1 commit into from
Feb 28, 2019
Merged
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 @@ -45,6 +45,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -93,9 +94,6 @@ public class Subscriber extends AbstractApiService {
private static final Duration UNARY_TIMEOUT = Duration.ofSeconds(60);
private static final Duration ACK_EXPIRATION_PADDING = Duration.ofSeconds(5);

private static final ScheduledExecutorService SHARED_SYSTEM_EXECUTOR =
InstantiatingExecutorProvider.newBuilder().setExecutorThreadCount(6).build().getExecutor();

private static final Logger logger = Logger.getLogger(Subscriber.class.getName());

private final String subscriptionName;
Expand Down Expand Up @@ -132,6 +130,8 @@ private Subscriber(Builder builder) {
.setLimitExceededBehavior(LimitExceededBehavior.ThrowException)
.build());

this.numPullers = builder.parallelPullCount;

executor = builder.executorProvider.getExecutor();
if (builder.executorProvider.shouldAutoClose()) {
closeables.add(
Expand All @@ -142,8 +142,16 @@ public void close() throws IOException {
}
});
}
alarmsExecutor = builder.systemExecutorProvider.getExecutor();
if (builder.systemExecutorProvider.shouldAutoClose()) {

ExecutorProvider systemExecutorProvider = builder.systemExecutorProvider;
if (systemExecutorProvider == null) {
systemExecutorProvider =
FixedExecutorProvider.create(
Executors.newScheduledThreadPool(Math.max(6, 2 * numPullers)));
}

alarmsExecutor = systemExecutorProvider.getExecutor();
if (systemExecutorProvider.shouldAutoClose()) {
closeables.add(
new AutoCloseable() {
@Override
Expand All @@ -153,7 +161,6 @@ public void close() throws IOException {
});
}

this.numPullers = builder.parallelPullCount;
TransportChannelProvider channelProvider = builder.channelProvider;
if (channelProvider.acceptsPoolSize()) {
channelProvider = channelProvider.withPoolSize(numPullers);
Expand All @@ -162,7 +169,7 @@ public void close() throws IOException {
try {
this.subStubSettings =
SubscriberStubSettings.newBuilder()
.setExecutorProvider(FixedExecutorProvider.create(alarmsExecutor))
.setExecutorProvider(systemExecutorProvider)
.setCredentialsProvider(builder.credentialsProvider)
.setTransportChannelProvider(channelProvider)
.setHeaderProvider(builder.headerProvider)
Expand Down Expand Up @@ -404,7 +411,7 @@ public static final class Builder {
FlowControlSettings.newBuilder().setMaxOutstandingElementCount(1000L).build();

ExecutorProvider executorProvider = DEFAULT_EXECUTOR_PROVIDER;
ExecutorProvider systemExecutorProvider = FixedExecutorProvider.create(SHARED_SYSTEM_EXECUTOR);
ExecutorProvider systemExecutorProvider = null;
TransportChannelProvider channelProvider =
SubscriptionAdminSettings.defaultGrpcTransportProviderBuilder()
.setMaxInboundMessageSize(MAX_INBOUND_MESSAGE_SIZE)
Expand Down