spring-cloud / spring-cloud-netflix

Integration with Netflix OSS components
http://cloud.spring.io/spring-cloud-netflix/
Apache License 2.0
4.87k stars 2.44k forks source link

Zuul: Configuring PoolingHttpClientConnectionManager with Time to Live? #1720

Closed GJL closed 7 years ago

GJL commented 7 years ago

Hi all,

I am using zuul to route requests to statically configured services according to the request path. The services behind zuul are addressed using DNS names. The DNS records can change rather frequently (e.g., daily).

I have seen in SimpleHostRoutingFilter that zuul uses PoolingHttpClientConnectionManager from Apache HttpComponents without configuring the time to live for the connections in the pool (see https://github.com/spring-cloud/spring-cloud-netflix/blob/master/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java#L238). Even if the DNS records change, the connection pool in zuul is keeping the connections to the old instances open. Depending on the load, it can take many hours until all the old connections are evicted from the connection pool.

I could subclass SimpleHostRoutingFilter and override the method newConnectionManager() to return my own instance of PoolingHttpClientConnectionManager with a configured TTL. Is there any other way to solve my problem, and does it make sense to add this feature to zuul?

Best, Gary

ryanjbaxter commented 7 years ago

I believe the you are right the only way to do this is to subclass SimpleHostRoutingFilter. Feel free to provide a PR with a better solution. Or we could try and address this issue along with fixing the issue in #1684.

asarkar commented 7 years ago

@ryanjbaxter SimpleHostRoutingFilter is not conditional in ZuulProxyConfiguration. Even if it's subclassed, how'd I replace the existing one without doing bean post processing? Do I set SimpleHostRoutingFilter.route.disable = true?

asarkar commented 7 years ago

@GJL There is no property called TTL in the PoolingHttpClientConnectionManager. What methods would you call to get the behavior you're asking for?

ryanjbaxter commented 7 years ago

Use @Primary

asarkar commented 7 years ago

@ryanjbaxter This doesn't apply to SimpleHostRoutingFilter? http://cloud.spring.io/spring-cloud-static/Dalston.RELEASE/#_disable_zuul_filters

ryanjbaxter commented 7 years ago

You can try that as well, I haven't tried it myself. I dont see why it wouldnt work

lalib commented 7 years ago

Hey there, I have the same problem like @GJL . Is there any updates or improvements?