Skip to content

Commit 777a5a2

Browse files
committed
feat: resizing channel pool size based on the work load
1 parent 1aaa80d commit 777a5a2

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.api.gax.batching.FlowController.LimitExceededBehavior;
2525
import com.google.api.gax.core.FixedCredentialsProvider;
2626
import com.google.api.gax.core.GoogleCredentialsProvider;
27+
import com.google.api.gax.grpc.ChannelPoolSettings;
2728
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
2829
import com.google.api.gax.retrying.RetrySettings;
2930
import com.google.api.gax.rpc.FixedHeaderProvider;
@@ -250,7 +251,13 @@ public Map<String, String> getJwtAudienceMapping() {
250251
/** Returns a builder for the default ChannelProvider for this service. */
251252
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
252253
return BigtableStubSettings.defaultGrpcTransportProviderBuilder()
253-
.setPoolSize(getDefaultChannelPoolSize())
254+
.setChannelPoolSettings(
255+
ChannelPoolSettings.builder()
256+
.setInitialChannelCount(2)
257+
.setMinRpcsPerChannel(1)
258+
.setMaxRpcsPerChannel(50)
259+
.setPreemptiveRefreshEnabled(true)
260+
.build())
254261
.setMaxInboundMessageSize(MAX_MESSAGE_SIZE)
255262
.setKeepAliveTime(Duration.ofSeconds(30)) // sends ping in this interval
256263
.setKeepAliveTimeout(
@@ -260,11 +267,6 @@ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProvi
260267
.setAttemptDirectPath(true);
261268
}
262269

263-
static int getDefaultChannelPoolSize() {
264-
// TODO: tune channels
265-
return 2 * Runtime.getRuntime().availableProcessors();
266-
}
267-
268270
@SuppressWarnings("WeakerAccess")
269271
public static TransportChannelProvider defaultTransportChannelProvider() {
270272
return defaultGrpcTransportProviderBuilder().build();
@@ -577,9 +579,7 @@ private Builder() {
577579
copyRetrySettings(baseDefaults.mutateRowSettings(), mutateRowSettings);
578580

579581
long maxBulkMutateElementPerBatch = 100L;
580-
// Enables bulkMutate to support 10 outstanding batches upto per channel or up to 20K entries.
581-
long maxBulkMutateOutstandingElementCount =
582-
Math.min(20_000L, 10L * maxBulkMutateElementPerBatch * getDefaultChannelPoolSize());
582+
long maxBulkMutateOutstandingElementCount = 20_000L;
583583

584584
bulkMutateRowsSettings =
585585
BigtableBatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor())
@@ -601,9 +601,7 @@ private Builder() {
601601

602602
long maxBulkReadElementPerBatch = 100L;
603603
long maxBulkReadRequestSizePerBatch = 400L * 1024L;
604-
// Enables bulkRead to support 10 outstanding batches per channel
605-
long maxBulkReadOutstandingElementCount =
606-
10L * maxBulkReadElementPerBatch * getDefaultChannelPoolSize();
604+
long maxBulkReadOutstandingElementCount = 20_000L;
607605

608606
bulkReadRowsSettings =
609607
BigtableBulkReadRowsCallSettings.newBuilder(new ReadRowsBatchingDescriptor())

0 commit comments

Comments
 (0)