HttpComponents PoolingHttpClientConnectionManager maxPerRoute and maxTotal?

前提是你 提交于 2019-12-03 08:40:02

问题


Can someone please explain to me what setMaxPerRoute(max) and setMaxTotal(max) do in reference to HttpComponents PoolingHttpClientConnectionManager?


回答1:


These settings control connection pool size.

  • setMaxTotal(max) defines the overal connection limit for a conneciton pool.
  • setMaxPerRoute(max) defines a connection limit per one HTTP route. In simple cases you can understand this as a per target host limit. Under the hood things are a bit more interesting: HttpClient maintains a couple of HttpRoute objects, which represent a chain of hosts each, like proxy1 -> proxy2 -> targetHost. Connections are pooled on per-route basis. In simple cases, when you're using default route-building mechanism and provide no proxy suport, your routes are likely to include target host only, so per-route connection pool limit effectively becomes per-host limit.

Example:

Suppose you have setMaxPerRoute(5) and setMaxTotal(20). That means you can simultameously use up to 5 connections for every target host: 5 connections with google.com, another 5 connections with oracle.com and so on. The total amount of open connections can't however exceed 20 regardless of the number of hosts you're communicating with.



来源:https://stackoverflow.com/questions/19347350/httpcomponents-poolinghttpclientconnectionmanager-maxperroute-and-maxtotal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!