From 777a5a2f412823b5f6fcc407463a339257f3791a Mon Sep 17 00:00:00 2001 From: Mattie Fu Date: Wed, 1 Jun 2022 15:53:59 -0400 Subject: [PATCH 1/2] feat: resizing channel pool size based on the work load --- .../v2/stub/EnhancedBigtableStubSettings.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java index 395ba52b08..2af8d64d0f 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java @@ -24,6 +24,7 @@ import com.google.api.gax.batching.FlowController.LimitExceededBehavior; import com.google.api.gax.core.FixedCredentialsProvider; import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.grpc.ChannelPoolSettings; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.FixedHeaderProvider; @@ -250,7 +251,13 @@ public Map getJwtAudienceMapping() { /** Returns a builder for the default ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return BigtableStubSettings.defaultGrpcTransportProviderBuilder() - .setPoolSize(getDefaultChannelPoolSize()) + .setChannelPoolSettings( + ChannelPoolSettings.builder() + .setInitialChannelCount(2) + .setMinRpcsPerChannel(1) + .setMaxRpcsPerChannel(50) + .setPreemptiveRefreshEnabled(true) + .build()) .setMaxInboundMessageSize(MAX_MESSAGE_SIZE) .setKeepAliveTime(Duration.ofSeconds(30)) // sends ping in this interval .setKeepAliveTimeout( @@ -260,11 +267,6 @@ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProvi .setAttemptDirectPath(true); } - static int getDefaultChannelPoolSize() { - // TODO: tune channels - return 2 * Runtime.getRuntime().availableProcessors(); - } - @SuppressWarnings("WeakerAccess") public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); @@ -577,9 +579,7 @@ private Builder() { copyRetrySettings(baseDefaults.mutateRowSettings(), mutateRowSettings); long maxBulkMutateElementPerBatch = 100L; - // Enables bulkMutate to support 10 outstanding batches upto per channel or up to 20K entries. - long maxBulkMutateOutstandingElementCount = - Math.min(20_000L, 10L * maxBulkMutateElementPerBatch * getDefaultChannelPoolSize()); + long maxBulkMutateOutstandingElementCount = 20_000L; bulkMutateRowsSettings = BigtableBatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor()) @@ -601,9 +601,7 @@ private Builder() { long maxBulkReadElementPerBatch = 100L; long maxBulkReadRequestSizePerBatch = 400L * 1024L; - // Enables bulkRead to support 10 outstanding batches per channel - long maxBulkReadOutstandingElementCount = - 10L * maxBulkReadElementPerBatch * getDefaultChannelPoolSize(); + long maxBulkReadOutstandingElementCount = 20_000L; bulkReadRowsSettings = BigtableBulkReadRowsCallSettings.newBuilder(new ReadRowsBatchingDescriptor()) From e76db0d3373029fe44ac5f103afd9525077738e1 Mon Sep 17 00:00:00 2001 From: Mattie Fu Date: Wed, 3 May 2023 17:25:40 -0400 Subject: [PATCH 2/2] update initial channel count to 10 --- .../bigtable/data/v2/stub/EnhancedBigtableStubSettings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java index fe2a503df6..53f02102f0 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java @@ -318,7 +318,7 @@ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProvi return BigtableStubSettings.defaultGrpcTransportProviderBuilder() .setChannelPoolSettings( ChannelPoolSettings.builder() - .setInitialChannelCount(2) + .setInitialChannelCount(10) .setMinRpcsPerChannel(1) .setMaxRpcsPerChannel(50) .setPreemptiveRefreshEnabled(true)