Skip to content

Commit 7fb1a09

Browse files
authored
feat: resizing channel pool size based on the work load (#1271)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/java-bigtable/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> ☕️ If you write sample code, please follow the [samples format]( https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
1 parent fadeafb commit 7fb1a09

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
@@ -23,6 +23,7 @@
2323
import com.google.api.gax.batching.FlowController.LimitExceededBehavior;
2424
import com.google.api.gax.core.FixedCredentialsProvider;
2525
import com.google.api.gax.core.GoogleCredentialsProvider;
26+
import com.google.api.gax.grpc.ChannelPoolSettings;
2627
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
2728
import com.google.api.gax.retrying.RetrySettings;
2829
import com.google.api.gax.rpc.FixedHeaderProvider;
@@ -315,7 +316,13 @@ public Map<String, String> getJwtAudienceMapping() {
315316
/** Returns a builder for the default ChannelProvider for this service. */
316317
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
317318
return BigtableStubSettings.defaultGrpcTransportProviderBuilder()
318-
.setPoolSize(getDefaultChannelPoolSize())
319+
.setChannelPoolSettings(
320+
ChannelPoolSettings.builder()
321+
.setInitialChannelCount(10)
322+
.setMinRpcsPerChannel(1)
323+
.setMaxRpcsPerChannel(50)
324+
.setPreemptiveRefreshEnabled(true)
325+
.build())
319326
.setMaxInboundMessageSize(MAX_MESSAGE_SIZE)
320327
.setKeepAliveTime(Duration.ofSeconds(30)) // sends ping in this interval
321328
.setKeepAliveTimeout(
@@ -325,11 +332,6 @@ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProvi
325332
.setAttemptDirectPath(true);
326333
}
327334

328-
static int getDefaultChannelPoolSize() {
329-
// TODO: tune channels
330-
return 2 * Runtime.getRuntime().availableProcessors();
331-
}
332-
333335
@SuppressWarnings("WeakerAccess")
334336
public static TransportChannelProvider defaultTransportChannelProvider() {
335337
return defaultGrpcTransportProviderBuilder().build();
@@ -658,9 +660,7 @@ private Builder() {
658660
copyRetrySettings(baseDefaults.mutateRowSettings(), mutateRowSettings);
659661

660662
long maxBulkMutateElementPerBatch = 100L;
661-
// Enables bulkMutate to support 10 outstanding batches upto per channel or up to 20K entries.
662-
long maxBulkMutateOutstandingElementCount =
663-
Math.min(20_000L, 10L * maxBulkMutateElementPerBatch * getDefaultChannelPoolSize());
663+
long maxBulkMutateOutstandingElementCount = 20_000L;
664664

665665
bulkMutateRowsSettings =
666666
BigtableBatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor())
@@ -682,9 +682,7 @@ private Builder() {
682682

683683
long maxBulkReadElementPerBatch = 100L;
684684
long maxBulkReadRequestSizePerBatch = 400L * 1024L;
685-
// Enables bulkRead to support 10 outstanding batches per channel
686-
long maxBulkReadOutstandingElementCount =
687-
10L * maxBulkReadElementPerBatch * getDefaultChannelPoolSize();
685+
long maxBulkReadOutstandingElementCount = 20_000L;
688686

689687
bulkReadRowsSettings =
690688
BigtableBulkReadRowsCallSettings.newBuilder(new ReadRowsBatchingDescriptor())

0 commit comments

Comments
 (0)