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: Add keepalive in grpc channelbuilder #2682

Merged
merged 3 commits into from
Nov 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

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 @@ -129,8 +129,10 @@ public void call(ClientContext context) {
// 256 MB, server has 256 MB limit.
private static final int MAX_MESSAGE_SIZE = 1 << 28;

static final long DIRECT_PATH_KEEP_ALIVE_TIME_SECONDS = 3600;
static final long DIRECT_PATH_KEEP_ALIVE_TIMEOUT_SECONDS = 20;
// Google Frontends limits keepalive calls at 30s by default.
static final long CHANNEL_KEEP_ALIVE_TIME_SECONDS = 30;
// Use this conservative values for timeout (10s)
static final long CHANNEL_KEEP_ALIVE_TIMEOUT_SECONDS = 10;

@VisibleForTesting
static final String PROJECT_ID_EMPTY_OR_NULL = "ProjectId must not be empty or null.";
Expand Down Expand Up @@ -588,9 +590,6 @@ public static ManagedChannel createNettyChannel(
+ " This is currently an experimental feature and should not be used in production.");

builder = ComputeEngineChannelBuilder.forAddress(host, options.getPort());
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
Expand Down Expand Up @@ -625,6 +624,10 @@ public static ManagedChannel createNettyChannel(
return builder
.idleTimeout(Long.MAX_VALUE, TimeUnit.SECONDS)
.maxInboundMessageSize(MAX_MESSAGE_SIZE)
.keepAliveTime(CHANNEL_KEEP_ALIVE_TIME_SECONDS, TimeUnit.SECONDS)
.keepAliveTimeout(CHANNEL_KEEP_ALIVE_TIMEOUT_SECONDS, TimeUnit.SECONDS)
// Default behavior Do not use keepalive without any outstanding rpc calls as it can add a
// bunch of load.
.userAgent(BigtableVersionInfo.CORE_USER_AGENT + "," + options.getUserAgent())
.intercept(interceptors)
.build();
Expand Down