RibbonLoadBalancingHttpClient pool size not configurable
RibbonLoadBalancingHttpClient uses the default HttpClientBuilder.
private final HttpClient delegate = HttpClientBuilder.create().build();
This defaults to a small maxConnTotal (20) and maxConnPerRoute (2)
There are IClientConfig settings for MaxTotalConnections and MaxConnectionsPerHost it would be great if these could be honoured.
Actually having a closer look with the debugger in 1.1.2 my zuul proxy with:
@Bean
public RibbonCommandFactory<?> ribbonCommandFactory(SpringClientFactory clientFactory) {
return new HttpClientRibbonCommandFactory(clientFactory);
}
It actually makes a new RibbonLoadBalancingHttpClient per request, and in turn a new delegate HttpClient. So the connection limits are not a problem but there will be a lot of unnecessary churn of HttpClient instances. I'm not familiar enough with this code to attempt a pull request or even suggest a fix.
It looks like the RibbonLoadBalancingHttpClient's aren't being cached in the context inside of the SpringClientFactory.
The Ribbon RestClient's do get cached in SpringClientFactory but I'm not sure why.
Good investigation. Both things look like they should be fixed. ~~RestClient's are cached because it is used to get the RestClient, therefore it gets cached.~~ They are in the child contexts, not cached.
See #1150 for caching.
Not sure what I was saying about caching there :-(
@nissel @stephlag
The following is a workaround for the Apache Client being created each time:
// other annotations like @EnableZuulProxy
@SpringBootApplication
@RibbonClients(defaultConfiguration = {RibbonClientConfiguration.class, DefaultConfig.class})
public class DemoapachehttpclientcreateApplication {
public static void main(String[] args) {
SpringApplication.run(DemoapachehttpclientcreateApplication.class, args);
}
}
class DefaultConfig {
@Bean
public RibbonLoadBalancingHttpClient ribbonLoadBalancingHttpClient(IClientConfig config, RetryHandler retryHandler) {
RibbonLoadBalancingHttpClient client = new RibbonLoadBalancingHttpClient();
client.initWithNiwsConfig(config);
client.setRetryHandler(retryHandler);
return client;
}
}
For OkHttp replace RibbonLoadBalancingHttpClient with OkHttpLoadBalancingClient.