OpenFeign / feign

Feign makes writing java http clients easier
Apache License 2.0
9.42k stars 1.92k forks source link

Http2Client: added clients cache #2405

Closed illia2m4ch closed 3 months ago

illia2m4ch commented 4 months ago

In case feign.Request.Options settings differ from the default native client java.net.http.HttpClient, a new client is created for each request, which leads to creation of a huge number of clients in memory. Added a map for caching soft references of clients.

velo commented 4 months ago

This makes me wonder, shouldn't feign be caching and reusing client at core level instead of the implementation?

illia2m4ch commented 4 months ago

This makes me wonder, shouldn't feign be caching and reusing client at core level instead of the implementation?

As I understand it, the problem is that feign has a rich set of parameters for each request (e.g. followRedirects), which may not match the parameters of the native client. Because of this, you need to create a new native client with the necessary parameters. That is, if a native client supports all the same parameters as feign, it does not have this problem.

Therefore, each native client will have its own key (its own set of parameters that it does not maintain at the request level) to retrieve the client. So I'm not sure if there is a better abstract solution at the core level of feign.