Skip to content

Commit

Permalink
[SCB-2805]change default settings for http keepalive timeout and idle…
Browse files Browse the repository at this point in the history
… timeout (#3927)
  • Loading branch information
liubao68 committed Sep 1, 2023
1 parent cd62391 commit edd9d79
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface HttpClientOptionsSPI {
boolean enabled();

/* config tag is used for group configurations, like ssl, address resolver, etc. set config tag to distinguish
* other clients configuration or read the common configuration. */
* other clients configuration or read the common configuration. */
String getConfigTag();

/* for config modules, the configuration is not ready, need set up config reader */
Expand Down Expand Up @@ -85,6 +85,7 @@ public interface HttpClientOptionsSPI {
int getHttp2MaxPoolSize();

boolean isUseAlpn();

/***************** proxy settings ***************************/
boolean isProxyEnable();

Expand All @@ -105,12 +106,13 @@ static HttpClientOptions createHttpClientOptions(HttpClientOptionsSPI spi) {
httpClientOptions.setProtocolVersion(spi.getHttpVersion());
httpClientOptions.setConnectTimeout(spi.getConnectTimeoutInMillis());
httpClientOptions.setIdleTimeout(spi.getIdleTimeoutInSeconds());
httpClientOptions.setReadIdleTimeout(spi.getIdleTimeoutInSeconds());
httpClientOptions.setWriteIdleTimeout(spi.getIdleTimeoutInSeconds());
httpClientOptions.setTryUseCompression(spi.isTryUseCompression());
httpClientOptions.setMaxWaitQueueSize(spi.getMaxWaitQueueSize());
httpClientOptions.setMaxPoolSize(spi.getMaxPoolSize());
httpClientOptions.setKeepAlive(spi.isKeepAlive());
httpClientOptions.setMaxHeaderSize(spi.getMaxHeaderSize());
httpClientOptions.setKeepAliveTimeout(spi.getKeepAliveTimeout());

if (spi.isProxyEnable()) {
ProxyOptions proxy = new ProxyOptions();
Expand All @@ -128,6 +130,8 @@ static HttpClientOptions createHttpClientOptions(HttpClientOptionsSPI spi) {
httpClientOptions.setHttp2MultiplexingLimit(spi.getHttp2MultiplexingLimit());
httpClientOptions.setHttp2MaxPoolSize(spi.getHttp2MaxPoolSize());
httpClientOptions.setHttp2KeepAliveTimeout(spi.getKeepAliveTimeout());
} else {
httpClientOptions.setKeepAliveTimeout(spi.getKeepAliveTimeout());
}

if (spi.isSsl()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
import com.netflix.config.DynamicPropertyFactory;

import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.net.TCPSSLOptions;

public final class TransportClientConfig {
private static final int DEFAULT_IDLE_TIME_OUT = 150;

private static final int DEFAULT_KEEP_ALIVE_TIME_OUT = 60;

private TransportClientConfig() {
}

Expand All @@ -46,12 +49,6 @@ public static int getHttp2MultiplexingLimit() {
.get();
}

public static int getHttp2ConnectionIdleTimeoutInSeconds() {
return DynamicPropertyFactory.getInstance()
.getIntProperty("servicecomb.rest.client.http2.idleTimeoutInSeconds", TCPSSLOptions.DEFAULT_IDLE_TIMEOUT)
.get();
}

public static boolean getUseAlpn() {
return DynamicPropertyFactory.getInstance()
.getBooleanProperty("servicecomb.rest.client.http2.useAlpnEnabled", true)
Expand All @@ -71,9 +68,15 @@ public static int getConnectionMaxPoolSize() {
.get();
}

public static int getHttp2ConnectionIdleTimeoutInSeconds() {
return DynamicPropertyFactory.getInstance()
.getIntProperty("servicecomb.rest.client.http2.connection.idleTimeoutInSeconds", DEFAULT_IDLE_TIME_OUT)
.get();
}

public static int getConnectionIdleTimeoutInSeconds() {
return DynamicPropertyFactory.getInstance()
.getIntProperty("servicecomb.rest.client.connection.idleTimeoutInSeconds", 30)
.getIntProperty("servicecomb.rest.client.connection.idleTimeoutInSeconds", DEFAULT_IDLE_TIME_OUT)
.get();
}

Expand All @@ -84,35 +87,17 @@ public static boolean getConnectionKeepAlive() {
}

public static int getConnectionKeepAliveTimeoutInSeconds() {
int result = DynamicPropertyFactory.getInstance()
return DynamicPropertyFactory.getInstance()
.getIntProperty("servicecomb.rest.client.connection.keepAliveTimeoutInSeconds",
-1)
DEFAULT_KEEP_ALIVE_TIME_OUT)
.get();
if (result >= 0) {
return result;
}
result = getConnectionIdleTimeoutInSeconds();
if (result > 1) {
// a bit shorter than ConnectionIdleTimeoutInSeconds
return result - 1;
}
return result;
}

public static int getHttp2ConnectionKeepAliveTimeoutInSeconds() {
int result = DynamicPropertyFactory.getInstance()
return DynamicPropertyFactory.getInstance()
.getIntProperty("servicecomb.rest.client.http2.connection.keepAliveTimeoutInSeconds",
-1)
DEFAULT_KEEP_ALIVE_TIME_OUT)
.get();
if (result >= 0) {
return result;
}
result = getHttp2ConnectionIdleTimeoutInSeconds();
if (result > 1) {
// a bit shorter than ConnectionIdleTimeoutInSeconds
return result - 1;
}
return result;
}

public static boolean getConnectionCompression() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void getConnectionMaxPoolSize() {

@Test
public void getConnectionIdleTimeoutInSeconds() {
Assertions.assertEquals(30, TransportClientConfig.getConnectionIdleTimeoutInSeconds());
Assertions.assertEquals(150, TransportClientConfig.getConnectionIdleTimeoutInSeconds());
}

@Test
Expand All @@ -63,7 +63,7 @@ public void getHttp2ConnectionMaxPoolSize() {

@Test
public void getHttp2ConnectionIdleTimeoutInSeconds() {
Assertions.assertEquals(0, TransportClientConfig.getHttp2ConnectionIdleTimeoutInSeconds());
Assertions.assertEquals(150, TransportClientConfig.getHttp2ConnectionIdleTimeoutInSeconds());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,25 +250,31 @@ private HttpServer createHttpServer() {

private HttpServerOptions createDefaultHttpServerOptions() {
HttpServerOptions serverOptions = new HttpServerOptions();
serverOptions.setIdleTimeout(TransportConfig.getConnectionIdleTimeoutInSeconds());
serverOptions.setCompressionSupported(TransportConfig.getCompressed());
serverOptions.setMaxHeaderSize(TransportConfig.getMaxHeaderSize());
serverOptions.setMaxFormAttributeSize(TransportConfig.getMaxFormAttributeSize());
serverOptions.setCompressionLevel(TransportConfig.getCompressionLevel());
serverOptions.setMaxChunkSize(TransportConfig.getMaxChunkSize());
serverOptions.setDecompressionSupported(TransportConfig.getDecompressionSupported());
serverOptions.setDecoderInitialBufferSize(TransportConfig.getDecoderInitialBufferSize());
serverOptions.setHttp2ConnectionWindowSize(TransportConfig.getHttp2ConnectionWindowSize());
serverOptions.setMaxInitialLineLength(TransportConfig.getMaxInitialLineLength());
if (endpointObject.isHttp2Enabled()) {
serverOptions.setUseAlpn(TransportConfig.getUseAlpn())
.setHttp2ConnectionWindowSize(TransportConfig.getHttp2ConnectionWindowSize())
.setIdleTimeout(TransportConfig.getHttp2ConnectionIdleTimeoutInSeconds())
.setReadIdleTimeout(TransportConfig.getHttp2ConnectionIdleTimeoutInSeconds())
.setWriteIdleTimeout(TransportConfig.getHttp2ConnectionIdleTimeoutInSeconds())
.setInitialSettings(new Http2Settings().setPushEnabled(TransportConfig.getPushEnabled())
.setMaxConcurrentStreams(TransportConfig.getMaxConcurrentStreams())
.setHeaderTableSize(TransportConfig.getHttp2HeaderTableSize())
.setInitialWindowSize(TransportConfig.getInitialWindowSize())
.setMaxFrameSize(TransportConfig.getMaxFrameSize())
.setMaxHeaderListSize(TransportConfig.getMaxHeaderListSize())
);
} else {
serverOptions.setIdleTimeout(TransportConfig.getConnectionIdleTimeoutInSeconds());
serverOptions.setReadIdleTimeout(TransportConfig.getConnectionIdleTimeoutInSeconds());
serverOptions.setWriteIdleTimeout(TransportConfig.getConnectionIdleTimeoutInSeconds());
}
if (endpointObject.isSslEnabled()) {
SSLOptionFactory factory =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import io.vertx.core.http.HttpServerOptions;

public final class TransportConfig {
public static final int DEFAULT_SERVER_CONNECTION_IDLE_TIMEOUT_SECOND = 60;
public static final int DEFAULT_SERVER_CONNECTION_IDLE_TIMEOUT_SECOND = 180;

public static final boolean DEFAULT_SERVER_COMPRESSION_SUPPORT = false;

Expand Down Expand Up @@ -103,6 +103,13 @@ public static int getConnectionIdleTimeoutInSeconds() {
.get();
}

public static int getHttp2ConnectionIdleTimeoutInSeconds() {
return DynamicPropertyFactory.getInstance()
.getIntProperty("servicecomb.rest.server.http2.connection.idleTimeoutInSeconds",
DEFAULT_SERVER_CONNECTION_IDLE_TIMEOUT_SECOND)
.get();
}

public static boolean getCompressed() {
return DynamicPropertyFactory.getInstance()
.getBooleanProperty("servicecomb.rest.server.compression", DEFAULT_SERVER_COMPRESSION_SUPPORT)
Expand Down

0 comments on commit edd9d79

Please sign in to comment.