Closed roycebranning closed 7 years ago
No it sets it on a specific apache http client.
Ok great - thanks.
Does this mean that the specific http client is responsible for tracking the number of current connections to be checked against this max-total-connections property?
The http client is the one executing the request for the proxy, so the maximum number of connections that client can make is set with max-total-connections
.
awesome
so then is there a way for me to access the http client information?
in other words: if I have max-total-connections set to 200, then the 201st request I receive gets blocked. Would there be a way for me to log how many requests are getting blocked?
Not right now. I know the pooled connection manager has a way to get stats from it but we have not exposed that in any way.
still playing around with these configurations.
are there any other zuul settings that could cause maxTotalConnections and maxPerRouteConnections to be ignored by the http client?
Currently setting both maxTotalConnections and maxPerRouteConnections variables to a value of 1 and sending 2 requests to the zuul gateway expecting that one would get blocked until the other returns. Instead they both get picked up immediately
Are you using zuul + service discovery/ribbon or setting the url
property directly?
zuul + service discover/ribbon
Can you show your configuration? Or do you have a sample app you can supply?
Here is the config for zuul (edge) server:
#Edge
info:
component: Edge Server
server:
port: 8765
tomcat:
remote_ip_header: x-forwarded-for
protocol_header: x-forwarded-proto
---
spring:
profiles: dev, test
zuul:
routes:
hello-world:
path: /hello-world/**
serviceId: hello-world
test-service
path:/tests-service/**
serviceId:test-service
host:
socket-timeout-millis: 5000
max-per-route-connections: 5
max-total-connections: 20
ribbon-isolation-strategy: semaphore
semaphore:
max-semaphores: 15
hystrix.command.default.execution.timeout.enabled: false
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 30000
ribbon:
ConnectTimeout: 3000
ReadTimeout: 30000
Could you please format the above properly so its easier to digest? https://help.github.com/articles/creating-and-highlighting-code-blocks/
Definitely - sorry about that
The zuul.host.*
properties will only be used for routes configured with urls and not serviceIds.
I believe you want to set max connections with Ribbon you want to do use serviceId.ribbon.MaxTotalConnections
and serviceId.ribbon.MaxConnectionsPerHost
.
The MaxTotalConnections & MaxConnectionsPerHost used for RibbonLoadBalancingHttpClient when call createDelegate
protected HttpClient createDelegate(IClientConfig config) {
return HttpClientBuilder.create()
// already defaults to 0 in builder, so resetting to 0 won't hurt
.setMaxConnTotal(config.getPropertyAsInteger(CommonClientConfigKey.MaxTotalConnections, 0))
// already defaults to 0 in builder, so resetting to 0 won't hurt
.setMaxConnPerRoute(config.getPropertyAsInteger(CommonClientConfigKey.MaxConnectionsPerHost, 0))
.disableCookieManagement()
.useSystemProperties() // for proxy
.build();
}
RibbonLoadBalancingHttpClient instanced by SpringClientFactory.
static <C> C instantiateWithConfig(AnnotationConfigApplicationContext context,
Class<C> clazz, IClientConfig config) {
C result = null;
try {
Constructor<C> constructor = clazz.getConstructor(IClientConfig.class);
result = constructor.newInstance(config);
} catch (Throwable e) {
// Ignored
}
if (result == null) {
result = BeanUtils.instantiate(clazz);
if (result instanceof IClientConfigAware) {
((IClientConfigAware) result).initWithNiwsConfig(config);
}
if (context != null) {
context.getAutowireCapableBeanFactory().autowireBean(result);
}
}
}
The IClientConfig object will be a DefaultClientConfigImpl instance,it isn't contain my config item MaxTotalConnections & MaxConnectionsPerHost in properties file. If RibbonLoadBalancingHttpClient has a Constructor with IClientConfig parameter, it will access the config item MaxTotalConnections & MaxConnectionsPerHost when createDelegate httpClient. Here is my solution:
public class CustomRibbonLoadBalancingHttpClient extends RibbonLoadBalancingHttpClient {
public CustomRibbonLoadBalancingHttpClient(final IClientConfig config) {
super(config, new DefaultServerIntrospector());
}
}
@seanlei what version of Spring Cloud are you using? This code recently change.
Thanks for your reply. @ryanjbaxter Spring Cloud version is Dalston.SR1. Spring-cloud-netflix-core 1.3.1.RELEASE Could I use latest version to fix this bug? I look into code of version 1.4.0.M1 and find the constructor with IClientConfig parameter was added to RibbonLoadBalancingHttpClient.I think it will be fine when i use 1.4.0.M1 version.Is this version stable? I can't depend an unstable version to my production env.
Yeah the Edgware.M1
release has the new code (which contains 1.4.0.M1). It is a milestone release so it is probably not production ready at this point, but it is more stable than a build snapshot would be.
http://cloud.spring.io/spring-cloud-static/Edgware.M1/#http-clients
waiting for your next stable release version
I'm trying to ultimately figure out if maxTotalConnections includes both proxy connections and connections to my internal microservices from the Zuul gateway.