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

feat: increase default number of channels when gRPC-GCP channel pool is enabled #1997

Merged
merged 19 commits into from Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -696,6 +696,7 @@ public static class Builder
private CloseableExecutorProvider asyncExecutorProvider;
private String compressorName;
private String emulatorHost = System.getenv("SPANNER_EMULATOR_HOST");
private boolean userSpecifiedNumChannels = false;
harshachinta marked this conversation as resolved.
Show resolved Hide resolved

private Builder() {
// Manually set retry and polling settings that work.
Expand Down Expand Up @@ -815,6 +816,7 @@ public Builder setInterceptorProvider(GrpcInterceptorProvider interceptorProvide
*/
public Builder setNumChannels(int numChannels) {
this.numChannels = numChannels;
this.userSpecifiedNumChannels = true;
return this;
}

Expand Down Expand Up @@ -1123,6 +1125,9 @@ public Builder setHost(String host) {
/** Enables gRPC-GCP extension with the default settings. */
public Builder enableGrpcGcpExtension() {
this.grpcGcpExtensionEnabled = true;
if (!userSpecifiedNumChannels) { // If numChannels is not set through options
harshachinta marked this conversation as resolved.
Show resolved Hide resolved
this.numChannels = 8; // default when grpc-gcp channel pool is enabled
harshachinta marked this conversation as resolved.
Show resolved Hide resolved
}
return this;
}
harshachinta marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
@@ -0,0 +1,80 @@
/*
harshachinta marked this conversation as resolved.
Show resolved Hide resolved
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.spanner;

import static com.google.common.truth.Truth.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class DefaultNumChannelsTest {

// With GRPC GCP channel pool enabled
@Test
public void testDefaultNumChannelsWithGrpcGcpEnabled() {
harshachinta marked this conversation as resolved.
Show resolved Hide resolved
SpannerOptions.Builder builder = SpannerOptions.newBuilder()
.setProjectId("test-project")
.enableGrpcGcpExtension();

SpannerOptions options = builder.build();
assertThat(options.getNumChannels()).isEqualTo(8);
harshachinta marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
public void testNumChannelsWithGrpcGcpEnabledLater() {
SpannerOptions.Builder builder = SpannerOptions.newBuilder()
.setProjectId("test-project")
.setNumChannels(5)
.enableGrpcGcpExtension();

SpannerOptions options = builder.build();
assertThat(options.getNumChannels()).isEqualTo(5);
}

@Test
public void testNumChannelsWithGrpcGcpEnabled() {
SpannerOptions.Builder builder = SpannerOptions.newBuilder()
.setProjectId("test-project")
.enableGrpcGcpExtension()
.setNumChannels(5);

SpannerOptions options = builder.build();
assertThat(options.getNumChannels()).isEqualTo(5);
}
harshachinta marked this conversation as resolved.
Show resolved Hide resolved

// Without enabling GRPC GCP channel pool
@Test
public void testDefaultNumChannelsWithOutGrpcGcpEnabled() {
SpannerOptions.Builder builder = SpannerOptions.newBuilder()
.setProjectId("test-project");

SpannerOptions options = builder.build();
assertThat(options.getNumChannels()).isEqualTo(4);
}

@Test
public void testNumChannelsWithOutGrpcGcpEnabled() {
SpannerOptions.Builder builder = SpannerOptions.newBuilder()
.setProjectId("test-project")
.setNumChannels(7);

SpannerOptions options = builder.build();
assertThat(options.getNumChannels()).isEqualTo(7);
}
}
harshachinta marked this conversation as resolved.
Show resolved Hide resolved