Spring cloud 使用zuul会发生大量关闭等待
当我使用springcloud zuul时,有大量TCP关闭等待状态发生,有人知道为什么会发生这种情况吗 这是我的zuul配置 母体聚甲醛Spring cloud 使用zuul会发生大量关闭等待,spring-cloud,netflix-zuul,Spring Cloud,Netflix Zuul,当我使用springcloud zuul时,有大量TCP关闭等待状态发生,有人知道为什么会发生这种情况吗 这是我的zuul配置 母体聚甲醛 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath />
</parent>
爪哇
当我访问时,创建了tcp链接,端口8082是hello服务器
tcp 0 0 ::ffff:192.168.120.20:8082 ::ffff:192.168.120.20:21505 ESTABLISHED 47968/java
tcp 0 0 ::ffff:192.168.120.20:21505 ::ffff:192.168.120.20:8082 ESTABLISHED 132689/java
tcp 0 0 ::ffff:192.168.120.20:8082 ::ffff:192.168.120.20:21510 ESTABLISHED 47968/java
tcp 0 0 ::ffff:192.168.120.20:21510 ::ffff:192.168.120.20:8082 ESTABLISHED 132689/java
tcp 0 0 ::ffff:192.168.120.20:8082 ::ffff:192.168.120.20:21504 ESTABLISHED 47968/java
tcp 0 0 ::ffff:192.168.120.20:21504 ::ffff:192.168.120.20:8082 ESTABLISHED 132689/java
然后就变了
tcp 0 0 ::ffff:192.168.120.20:8082 ::ffff:192.168.120.20:21505 FIN_WAIT2 -
tcp 1 0 ::ffff:192.168.120.20:21505 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
tcp 0 0 ::ffff:192.168.120.20:8082 ::ffff:192.168.120.20:21510 FIN_WAIT2 -
tcp 0 0 ::ffff:192.168.120.20:21510 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
tcp 0 0 ::ffff:192.168.120.20:8082 ::ffff:192.168.120.20:21504 FIN_WAIT2 -
tcp 1 0 ::ffff:192.168.120.20:21504 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
最后,
tcp 1 0 ::ffff:192.168.120.20:21505 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
tcp 1 0 ::ffff:192.168.120.20:21504 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
tcp 1 0 ::ffff:192.168.120.20:21510 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
此状态将持续数小时。
CLOSE\u WAIT
如下所述:
此端点已收到来自远程端点的关闭请求,此TCP现在正在等待来自本地应用程序的连接终止请求
Ribbon使用连接池向上游发送请求。每次,它都会释放连接而不是关闭连接,以避免建立新连接的开销
池中的连接通过配置ribbon.PoolKeepAliveTime
具有活动时间,默认值为15*60秒
public class DefaultClientConfigImpl implements IClientConfig {
public static final long DEFAULT_POOL_KEEP_ALIVE_TIME = 15 * 60L;
public static final TimeUnit DEFAULT_POOL_KEEP_ALIVE_TIME_UNITS = TimeUnit.SECONDS;
}
public class OkHttpRibbonConfiguration {
@Value("${ribbon.client.name}")
private String name = "client";
@Configuration
protected static class OkHttpClientConfiguration {
private OkHttpClient httpClient;
@Bean
@ConditionalOnMissingBean(ConnectionPool.class)
public ConnectionPool httpClientConnectionPool(IClientConfig config, OkHttpClientConnectionPoolFactory connectionPoolFactory) {
Integer maxTotalConnections = config.getPropertyAsInteger(
CommonClientConfigKey.MaxTotalConnections,
DefaultClientConfigImpl.DEFAULT_MAX_TOTAL_CONNECTIONS);
Object timeToLiveObj = config
.getProperty(CommonClientConfigKey.PoolKeepAliveTime);
Long timeToLive = DefaultClientConfigImpl.DEFAULT_POOL_KEEP_ALIVE_TIME;
Object ttlUnitObj = config
.getProperty(CommonClientConfigKey.PoolKeepAliveTimeUnits);
TimeUnit ttlUnit = DefaultClientConfigImpl.DEFAULT_POOL_KEEP_ALIVE_TIME_UNITS;
if (timeToLiveObj instanceof Long) {
timeToLive = (Long) timeToLiveObj;
}
if (ttlUnitObj instanceof TimeUnit) {
ttlUnit = (TimeUnit) ttlUnitObj;
}
return connectionPoolFactory.create(maxTotalConnections, timeToLive, ttlUnit);
}
}
感谢您的回答,在我的环境中,关闭等待状态持续数小时,更改参数
ribbon.PoolKeepAliveTime
是没有用的。当我删除以下配置时,问题消失了,但仍然不知道为什么,我将继续关注它。ribbon.MaxAutoRetries=0 ribbon.MaxAutoRetriesNextServer=1 ribbon.OktoretryonalOperations=false ribbon.httpclient.enabled=false ribbon.okhttp.enabled=true
tcp 0 0 ::ffff:192.168.120.20:8082 ::ffff:192.168.120.20:21505 FIN_WAIT2 -
tcp 1 0 ::ffff:192.168.120.20:21505 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
tcp 0 0 ::ffff:192.168.120.20:8082 ::ffff:192.168.120.20:21510 FIN_WAIT2 -
tcp 0 0 ::ffff:192.168.120.20:21510 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
tcp 0 0 ::ffff:192.168.120.20:8082 ::ffff:192.168.120.20:21504 FIN_WAIT2 -
tcp 1 0 ::ffff:192.168.120.20:21504 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
tcp 1 0 ::ffff:192.168.120.20:21505 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
tcp 1 0 ::ffff:192.168.120.20:21504 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
tcp 1 0 ::ffff:192.168.120.20:21510 ::ffff:192.168.120.20:8082 CLOSE_WAIT 132689/java
public class DefaultClientConfigImpl implements IClientConfig {
public static final long DEFAULT_POOL_KEEP_ALIVE_TIME = 15 * 60L;
public static final TimeUnit DEFAULT_POOL_KEEP_ALIVE_TIME_UNITS = TimeUnit.SECONDS;
}
public class OkHttpRibbonConfiguration {
@Value("${ribbon.client.name}")
private String name = "client";
@Configuration
protected static class OkHttpClientConfiguration {
private OkHttpClient httpClient;
@Bean
@ConditionalOnMissingBean(ConnectionPool.class)
public ConnectionPool httpClientConnectionPool(IClientConfig config, OkHttpClientConnectionPoolFactory connectionPoolFactory) {
Integer maxTotalConnections = config.getPropertyAsInteger(
CommonClientConfigKey.MaxTotalConnections,
DefaultClientConfigImpl.DEFAULT_MAX_TOTAL_CONNECTIONS);
Object timeToLiveObj = config
.getProperty(CommonClientConfigKey.PoolKeepAliveTime);
Long timeToLive = DefaultClientConfigImpl.DEFAULT_POOL_KEEP_ALIVE_TIME;
Object ttlUnitObj = config
.getProperty(CommonClientConfigKey.PoolKeepAliveTimeUnits);
TimeUnit ttlUnit = DefaultClientConfigImpl.DEFAULT_POOL_KEEP_ALIVE_TIME_UNITS;
if (timeToLiveObj instanceof Long) {
timeToLive = (Long) timeToLiveObj;
}
if (ttlUnitObj instanceof TimeUnit) {
ttlUnit = (TimeUnit) ttlUnitObj;
}
return connectionPoolFactory.create(maxTotalConnections, timeToLive, ttlUnit);
}
}