-
Notifications
You must be signed in to change notification settings - Fork 118
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(spanner): set manual affinity incase of gRPC-GCP extenstion #3215
feat(spanner): set manual affinity incase of gRPC-GCP extenstion #3215
Conversation
@@ -529,6 +531,10 @@ private static String parseGrpcGcpApiConfig() { | |||
private static GcpManagedChannelOptions grpcGcpOptionsWithMetrics(SpannerOptions options) { | |||
GcpManagedChannelOptions grpcGcpOptions = | |||
MoreObjects.firstNonNull(options.getGrpcGcpOptions(), new GcpManagedChannelOptions()); | |||
GcpChannelPoolOptions gcpChanelPoolOptions = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GcpChannelPoolOptions gcpChanelPoolOptions = | |
GcpChannelPoolOptions gcpChannelPoolOptions = |
.getCallOptions() | ||
.withOption( | ||
GcpManagedChannel.AFFINITY_KEY, | ||
Option.CHANNEL_HINT.getLong(options).toString())); |
There was a problem hiding this comment.
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
java-spanner/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractReadContext.java
Line 342 in e859b29
this.channelHint = |
context = context.withChannelAffinity(Option.CHANNEL_HINT.getLong(options).intValue()); | ||
|
||
// Set channel affinity in gRPC-GCP. This is a no-op for GAX. |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Earlier, gRPC-GCP maintains affinity using the ApiConfig by looking into the gRPC messages to get an affinity key.
This PR sets the affinity manually to gRPC-GCP via call options. Reason - With multiplexed sessions we need to maintain transaction to channel affinity, and with regular sessions we need to maintain session to channel affinity.
Setting manual affinity will override the API config setting.
References: