Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Fix InstantiatingGrpcChannelProvider's channel pool to play nicely wi…
Browse files Browse the repository at this point in the history
…th DirectPath (#798)

* Fix InstantiatingGrpcChannelProvider's channel pool to play nicely with DirectPath

By default grpclb strategy for DirectPath is to create a subchannel for
every address resolved by the grpclb and round robin over them.
Unfortunately this doesn't work well when Channel pooling is enable in
the InstantiatingGrpcChannelProvider, which will create multiple
ManagedChannels, each containing a bunch of subchannels.

Since channel pooling is needed to have good performance targeting CFEs,
the solution here is to force each ManagedChannel to pick a single
subchannel. Thus preserving the CFE behavior of a single ManagedChannel
only containing a single subchannel.

* Always use pick_first even if poolSize = 1

* split up service config

* reformat service config

* added a ref for the service config proto
  • Loading branch information
igorbernstein2 committed Oct 16, 2019
1 parent 31b44b1 commit 778c8e3
Showing 1 changed file with 20 additions and 0 deletions.
Expand Up @@ -42,6 +42,7 @@
import com.google.auth.oauth2.ComputeEngineCredentials;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.alts.ComputeEngineChannelBuilder;
Expand Down Expand Up @@ -238,6 +239,25 @@ private ManagedChannel createSingleChannel() throws IOException {
// Will be overridden by user defined values if any.
builder.keepAliveTime(DIRECT_PATH_KEEP_ALIVE_TIME_SECONDS, TimeUnit.SECONDS);
builder.keepAliveTimeout(DIRECT_PATH_KEEP_ALIVE_TIMEOUT_SECONDS, TimeUnit.SECONDS);

// When channel pooling is enabled, force the pick_first grpclb strategy.
// This is necessary to avoid the multiplicative effect of creating channel pool with
// `poolSize` number of `ManagedChannel`s, each with a `subSetting` number of number of subchannels.
// See the service config proto definition for more details:
// https://github.com/grpc/grpc-proto/blob/master/grpc/service_config/service_config.proto#L182
ImmutableMap<String, Object> pickFirstStrategy =
ImmutableMap.<String, Object>of("pick_first", ImmutableMap.of());

ImmutableMap<String, Object> childPolicy =
ImmutableMap.<String, Object>of("childPolicy", ImmutableList.of(pickFirstStrategy));

ImmutableMap<String, Object> grpcLbPolicy =
ImmutableMap.<String, Object>of("grpclb", childPolicy);

ImmutableMap<String, Object> loadBalancingConfig =
ImmutableMap.<String, Object>of("loadBalancingConfig", ImmutableList.of(grpcLbPolicy));

builder.defaultServiceConfig(loadBalancingConfig);
} else {
builder = ManagedChannelBuilder.forAddress(serviceAddress, port);
}
Expand Down

0 comments on commit 778c8e3

Please sign in to comment.