首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >大量的CLOSE_WAIT是通过使用zuul来实现的。

大量的CLOSE_WAIT是通过使用zuul来实现的。
EN

Stack Overflow用户
提问于 2018-06-29 09:08:47
回答 1查看 1.5K关注 0票数 0

当我使用springcloud时,会出现大量的TCP CLOSE_WAIT状态,有人知道为什么会发生这种情况吗?

这是我的zuul配置

亲本pom

代码语言:javascript
复制
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath />
</parent>
  1. pom.xml org.springframework.boot弹簧-启动器-执行器- org.springframework.cloud弹簧-启动器-netflix-eureka-客户端org.springframework.cloud弹簧-云启动-netflix-zuul com.squareup.okhttp3 org.springframework.cloud弹簧-云依赖项Edgware.SR2 pom导入
  2. application.properties 名称=zuul-server-test eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port} eureka.instance.leaseRenewalIntervalInSeconds=5 eureka.instance.leaseExpirationDurationInSeconds=10 eureka.client.serviceUrl.defaultZone=http://127.0.0.1:8080/eureka/ zuul.add-host-header=true zuul.敏感-header= hystrix.command.default.execution.timeout.enable=true hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=60000 zuul.host.CONNECT-millis=60000 zuul.host.socket-timeout-milllis=60000 ribbon.eureka.enabled=true丝带。ReadTimeout=60000 ribbon.ConnectTimeout=30000 ribbon.MaxAutoRetries=0 ribbon.MaxAutoRetriesNextServer=1 ribbon.OkToRetryOnAllOperations=false ribbon.httpclient.enabled=false ribbon.OkToRetryOnAllOperations=false ribbon.httpclient.enabled=false ribbon.okhttp.enabled=true hello.path=/hello.path=/hello/* zuul.routes.hello.sensitiveHeaders= zuul.Update.hello.service-id=hello-server

java

代码语言:javascript
复制
    @SpringBootApplication
    @EnableDiscoveryClient
    @EnableZuulProxy
    public class DevcloudZuulApplication {
        public static void main(String[] args) {
            SpringApplication.run(DevcloudZuulApplication.class, args);
        }
    }

当我访问http://localhost:8081/hello/index.html时,创建了tcp链接,端口8082是hello服务器。

代码语言:javascript
复制
    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

然后它就变了

代码语言:javascript
复制
    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  

最后,

代码语言:javascript
复制
    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 

这种状态将持续数小时。

EN

回答 1

Stack Overflow用户

发布于 2018-06-29 23:37:21

这里描述的CLOSE_WAITTCP连接状态

此端点已收到来自远程端点的关闭请求,此TCP现在正在等待来自本地应用程序的连接终止请求。

丝带使用连接池向上游发送请求。每次,它都会释放连接而不是关闭连接,以避免建立新连接的开销。

通过配置默认值为15 *60秒的ribbon.PoolKeepAliveTime,池中的连接具有活动时间。

代码语言:javascript
复制
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);
    }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51098173

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档