Closed brenuart closed 9 years ago
@Lazy
could work, but I think it would need to be combined with a change to FeignClientFactoryBean
that currently injects the client. It's needed if you don't use ribbon, but it is ignored if you use ribbon.
Actually, I was looking at the wrong client in FeignClientFactoryBean
, so it may not require the rework there.
@Lazy
on
org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration.ribbonRestClient()
does the job.
I made a checkout of the current sources and applied the change. The RestClient
and the underlying Apache HttpClient infrastructure are not created anymore.
how about a pull request?
Ok changes applied. Sorry, but first time I do this with Github - still have to be familiar with this tool ;-) Hope everything is ok. Doesn't build however... Should I configure my Github environment or else?
Please note that the same could be done to RibbonAutoConfiguration.RibbonClientConfig.restTemplateCustomizer()
... What do you think?
@spencergibb Now that you merged the PR - can we close this issue?
When used together with Ribbon, feign clients delegate the actual call to
feign.ribbon.LBClient
. In SpringCloud environment, the latter is created byorg.springframework.cloud.netflix.feign.ribbon.SpringLBClientFactory
that relies onorg.springframework.cloud.netflix.ribbon.SpringClientFactory
to create a child application context per client.The
SpringClientFactory
is responsible to build the child application context hosting all components required by the feign and ribbon components. It also unconditionally addsorg.springframework.cloud.netflix.ribbon.RibbonClientConfiguration
in the context.Unfortunately, the latter causes the creation of a
RestClient
instance never used in this context. RestClient is a pretty heavy component as it comes with an Apache HttpClient and its connection pool behind the scenes... We can see traces of this by looking at the metrics exported by the /metrics actuator endpoint:They are created by
com.netflix.http4.NamedConnectionPool
. Their value stay at 0 whatever the activity.Proposition is to mark the factory method creating the RestClient as
@Lazy
inorg.springframework.cloud.netflix.ribbon.RibbonClientConfiguration
:Because of the @Lazy the
RestClient
will still be created if ever required by any other component.Side question: is there any other components in that configuration class that should also be considered optional and therefore be annotated with
@Lazy
?