spring cloud zuul-哪些连接参数在什么时候工作?

q1qsirdb  于 2021-07-07  发布在  Java
关注(0)|答案(0)|浏览(280)

根据这条评论,zuul提供了以下几种配置参数: zuul.host.* :包括。 max-per-route-connections 以及 max-total-connections . 只有在显式声明路由时才有相关的,如下所示:

---
zuul:
  host:
    max-per-route-connections: 500
    max-total-connections: 5000
  routes:
    my-service:
      path: /my-service/v1/**
      url: http://some-api/v1/

使用时 Ribbon 一起 Eureka ,的 serviceId.ribbon.* 应该使用参数,或者更全局地使用(afaik) ribbon.* 例如 ribbon.MaxConnectionsPerHost . 这些设置将应用于所有功能区客户端。例如,如果我们有:

---
ribbon:
  MaxConnectionsPerHost: 10
  MaxTotalConnections: 100
  ReadTimeout: 3000

如果servicea是通过eureka注册的,那么zuul应该创建一个 RibbonCommand 对于具有上述设置的请求。这是在 org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter#forward :

protected ClientHttpResponse forward(RibbonCommandContext context) throws Exception {
    Map<String, Object> info = this.helper.debug(context.getMethod(),
            context.getUri(), context.getHeaders(), context.getParams(),
            context.getRequestEntity());

        RibbonCommand command = this.ribbonCommandFactory.create(context);
    try {
        ClientHttpResponse response = command.execute();
        this.helper.appendDebug(info, response.getRawStatusCode(),
                response.getHeaders());
        return response;
    }
    catch (HystrixRuntimeException ex) {
        return handleException(info, ex);
    }

}

到现在为止,一直都还不错。不过,我无法证实这种行为。
在我的应用程序中,我设置了以下参数:

-Dspring.profiles.active=test
-Dspring.cloud.config.label=local
-Deureka.client.defaultZone.serviceUrl=http://localhost:8761/eureka
-Deureka.instance.hostname=${spring.application.name}
-Dzuul.host.max-total-connections=2
-Dzuul.host.max-per-route-connections=2
-Dribbon.MaxTotalConnections=2
-Dribbon.MaxConnectionsPerHost=2
-Dribbon.MaxTotalHttpConnections=2

以及以下配置:

hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 150000
          strategy: SEMAPHORE
        timeout:
          enabled: false

之后,当我第一次对给定的 service ,我看到了 this.ribbonCommandFactory.create(context) 一个新的 HttpClientConnectionManager 已创建( org.springframework.cloud.netflix.ribbon.apache.HttpClientRibbonConfiguration.ApacheHttpClientConfiguration#httpClientConnectionManager ),它有 maxTotalConnections = 2 以及 maxConnectionsPerHost = 2 .
之后,我在前面设置了一个线程断点 command.execute() . 我发出了>2个请求,希望从第三个开始的所有请求都抱怨无法获取信号量来执行。
有什么好处?执行期间是否检查此设置?我上面的描述正确吗?哪些设置在 ribbon 正在与一起使用 serviceId 什么?
我知道springcloudzuul处于维护模式,我想尽快切换到springcloudgateway,但我仍然想了解这种行为。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题