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

Enable HTTP keep alive by default #1873

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
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 @@ -329,10 +329,10 @@ public static class Builder<T extends Builder<T>> {
private Consumer<ManagedChannelBuilder<?>> channelInitializer;
private Duration healthCheckAttemptTimeout;
private Duration healthCheckTimeout;
private boolean enableKeepAlive;
private Duration keepAliveTime;
private Duration keepAliveTimeout;
private boolean keepAlivePermitWithoutStream;
private boolean enableKeepAlive = true;
private Duration keepAliveTime = Duration.ofSeconds(30);
private Duration keepAliveTimeout = Duration.ofSeconds(15);
private boolean keepAlivePermitWithoutStream = true;
private Duration rpcTimeout = DEFAULT_RPC_TIMEOUT;
private Duration connectionBackoffResetFrequency = DEFAULT_CONNECTION_BACKOFF_RESET_FREQUENCY;
private Duration grpcReconnectFrequency = DEFAULT_GRPC_RECONNECT_FREQUENCY;
Expand Down Expand Up @@ -607,6 +607,8 @@ public T setHealthCheckTimeout(Duration healthCheckTimeout) {
* Enables keep alive ping from client to the server, which can help drop abruptly closed
* connections faster.
*
* <p>Default is true
*
* @return {@code this}
*/
public T setEnableKeepAlive(boolean enableKeepAlive) {
Expand All @@ -619,6 +621,8 @@ public T setEnableKeepAlive(boolean enableKeepAlive) {
* see if the transport is still alive. If set below 10s, a minimum value of 10s will be used
* instead.
*
* <p>Default is 30s
*
* @return {@code this}
*/
public T setKeepAliveTime(Duration keepAliveTime) {
Expand All @@ -630,6 +634,8 @@ public T setKeepAliveTime(Duration keepAliveTime) {
* After having pinged for keepalive check, the client waits for a duration of Timeout and if no
* activity is seen even after that the connection is closed.
*
* <p>Default is 15s
*
* @return {@code this}
*/
public T setKeepAliveTimeout(Duration keepAliveTimeout) {
Expand All @@ -641,6 +647,8 @@ public T setKeepAliveTimeout(Duration keepAliveTimeout) {
* If true, client sends keepalive pings even with no active RPCs. If false, when there are no
* active RPCs, Time and Timeout will be ignored and no keepalive pings will be sent. * @return
*
* <p>Default is true
*
* @return {@code this}
*/
public T setKeepAlivePermitWithoutStream(boolean keepAlivePermitWithoutStream) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
*
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Modifications copyright (C) 2017 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this material 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 io.temporal.serviceclient.functional;

import static org.junit.Assert.assertEquals;

import io.temporal.serviceclient.WorkflowServiceStubsOptions;
import io.temporal.testing.internal.SDKTestWorkflowRule;
import java.time.Duration;
import org.junit.Rule;
import org.junit.Test;

public class KeepAliveTest {
@Rule public SDKTestWorkflowRule testWorkflowRule = SDKTestWorkflowRule.newBuilder().build();

@Test
public void testKeepAliveOnByDefault() {
WorkflowServiceStubsOptions options = testWorkflowRule.getWorkflowServiceStubs().getOptions();
assertEquals(true, options.getEnableKeepAlive());
assertEquals(true, options.getKeepAlivePermitWithoutStream());
assertEquals(Duration.ofSeconds(30), options.getKeepAliveTime());
assertEquals(Duration.ofSeconds(15), options.getKeepAliveTimeout());
}
}