According to this comment, Zuul offers the following kinds of configuration parameters:
zuul.host.*: these include e.g.max-per-route-connectionsandmax-total-connections. There are only relevant when routes are explicitly declared, as follows:
---
zuul:
host:
max-per-route-connections: 500
max-total-connections: 5000
routes:
my-service:
path: /my-service/v1/**
url: http://some-api/v1/
- When using
Ribbontogether withEureka, theserviceId.ribbon.*parameters should be used - or, more globally (AFAIK)ribbon.*e.g.ribbon.MaxConnectionsPerHost. These settings would apply for all Ribbon clients. So, if we have for example:
---
ribbon:
MaxConnectionsPerHost: 10
MaxTotalConnections: 100
ReadTimeout: 3000
and serviceA is registered via Eureka, then Zuul should create a RibbonCommand for the request with the above settings. This is seen in 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);
}
}
So far so good. Except, I can't validate this behaviour.
In my application, I've set the following parameters:
-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
as well as the following config:
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 150000
strategy: SEMAPHORE
timeout:
enabled: false
Afterwards, when I make the first request against the given service, I see that this.ribbonCommandFactory.create(context) a new HttpClientConnectionManager is created (org.springframework.cloud.netflix.ribbon.apache.HttpClientRibbonConfiguration.ApacheHttpClientConfiguration#httpClientConnectionManager), which has maxTotalConnections = 2 and maxConnectionsPerHost = 2.
Afterwards, I set a thread breakpoint just before command.execute(). I fire off >2 requests, expecting everything from the third onwards to complain about not being able to acquire a semaphore for execution.
What gives? Is this setting being checked during execute? Is my description above even correct? Which settings really apply when ribbon is being used with serviceIds?
I know that Spring Cloud Zuul is in maintenance mode, and I would like to switch to Spring Cloud Gateway ASAP, but I would still like to understand this behaviour.