Skip to content

Commit

Permalink
feat: resizing channel pool size based on the work load (#1271)
Browse files Browse the repository at this point in the history
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://togithub.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://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
  • Loading branch information
mutianf committed May 3, 2023
1 parent fadeafb commit 7fb1a09
Showing 1 changed file with 10 additions and 12 deletions.
Expand Up @@ -23,6 +23,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;
Expand Down Expand Up @@ -315,7 +316,13 @@ public Map<String, String> 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(10)
.setMinRpcsPerChannel(1)
.setMaxRpcsPerChannel(50)
.setPreemptiveRefreshEnabled(true)
.build())
.setMaxInboundMessageSize(MAX_MESSAGE_SIZE)
.setKeepAliveTime(Duration.ofSeconds(30)) // sends ping in this interval
.setKeepAliveTimeout(
Expand All @@ -325,11 +332,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();
Expand Down Expand Up @@ -658,9 +660,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())
Expand All @@ -682,9 +682,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())
Expand Down

0 comments on commit 7fb1a09

Please sign in to comment.