本文介绍了HttpComponents PoolingHttpClientConnectionManager maxPerRoute和maxTotal?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释一下 setMaxPerRoute(max) setMaxTotal(max)参考HttpComponents PoolingHttpClientConnectionManager?

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

推荐答案

这些设置控制连接池大小。

These settings control connection pool size.


  • setMaxTotal(max)定义连接池的总连接限制。

  • setMaxPerRoute(max)定义每条HTTP路由的连接限制。在简单的情况下,您可以将其理解为每个目标主机限制。引擎盖下的东西更有趣: HttpClient 维护一些 HttpRoute 对象,它们代表一系列主机每个,如 proxy1 - > proxy2 - > targetHost 。连接按路由汇集。在简单的情况下,当您使用默认路由构建机制并且不提供代理支持时,您的路由可能仅包括目标主机,因此每个路由连接池限制实际上变为每个主机限制。

  • 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.

示例:

假设你有 setMaxPerRoute(5) setMaxTotal(20)。这意味着您可以同时为每个目标主机使用最多5个连接:5个与google.com的连接,另外5个与oracle.com的连接,依此类推。但是,无论您正在与之通信的主机数量是多少,打开的连接总数都不能超过20个。

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.

这篇关于HttpComponents PoolingHttpClientConnectionManager maxPerRoute和maxTotal?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 20:08