Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@
import com.google.api.pathtemplate.PathTemplate;
import com.google.cloud.RetryHelper;
import com.google.cloud.RetryHelper.RetryHelperException;
import com.google.cloud.grpc.GcpManagedChannel;
import com.google.cloud.grpc.GcpManagedChannelBuilder;
import com.google.cloud.grpc.GcpManagedChannelOptions;
import com.google.cloud.grpc.GcpManagedChannelOptions.GcpChannelPoolOptions;
import com.google.cloud.grpc.GcpManagedChannelOptions.GcpMetricsOptions;
import com.google.cloud.grpc.GrpcTransportOptions;
import com.google.cloud.spanner.AdminRequestsPerMinuteExceededException;
Expand Down Expand Up @@ -529,6 +531,10 @@ private static String parseGrpcGcpApiConfig() {
private static GcpManagedChannelOptions grpcGcpOptionsWithMetrics(SpannerOptions options) {
GcpManagedChannelOptions grpcGcpOptions =
MoreObjects.firstNonNull(options.getGrpcGcpOptions(), new GcpManagedChannelOptions());
GcpChannelPoolOptions gcpChanelPoolOptions =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GcpChannelPoolOptions gcpChanelPoolOptions =
GcpChannelPoolOptions gcpChannelPoolOptions =
GcpChannelPoolOptions.newBuilder()
.setAffinityKeyLifetime(java.time.Duration.ofMinutes(60L))
.build();
GcpMetricsOptions metricsOptions =
MoreObjects.firstNonNull(
grpcGcpOptions.getMetricsOptions(), GcpMetricsOptions.newBuilder().build());
Expand All @@ -542,6 +548,7 @@ private static GcpManagedChannelOptions grpcGcpOptionsWithMetrics(SpannerOptions
}
return GcpManagedChannelOptions.newBuilder(grpcGcpOptions)
.withMetricsOptions(metricsOptionsBuilder.build())
.withChannelPoolOptions(gcpChanelPoolOptions)
.build();
}

Expand Down Expand Up @@ -1950,7 +1957,17 @@ <ReqT, RespT> GrpcCallContext newCallContext(
boolean routeToLeader) {
GrpcCallContext context = GrpcCallContext.createDefault();
if (options != null) {
// Set channel affinity in GAX. This is a no-op for gRPC-GCP.
context = context.withChannelAffinity(Option.CHANNEL_HINT.getLong(options).intValue());

// Set channel affinity in gRPC-GCP. This is a no-op for GAX.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is it possible to only do this if grpc-gcp is being used? I know that it is a no-op for gax, and so does not affect anything in that way, but context.withCallOptions(..) always creates a new CallContext instance. That means that we reserve a small bit of additional memory for every RPC that we invoke that then needs to be cleaned up again afterwards. (And yes, that's a bit of a pre-emptive optimization, so if it is not possible or hard, then please ignore this comment, but if there's a simple if-condition that we can use, then let's do that.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made changes to do it only when grpcgcp is enabled. Can you please take a look?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

context =
context.withCallOptions(
context
.getCallOptions()
.withOption(
GcpManagedChannel.AFFINITY_KEY,
Option.CHANNEL_HINT.getLong(options).toString()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This channel hint can be any random Long, meaning that we might be using a very large range of different channel hints. That again means that we might be adding an unbounded set of channel hints to the map in grpc-gcp. We should add a computation here that makes sure that the set of hints is limited (e.g. do something like hint % options.getNumChannels()).

See

}
if (compressorName != null) {
// This sets the compressor for Client -> Server.
Expand Down