使 Python 'requests' 模块的连接池大小非常大有什么缺点?

What are the drawbacks for making the connection pool size for the Python 'requests' module very large?

在将 HTTPAdapter 挂载到 requests.Session() 上时,我遇到了连接最终被丢弃的问题,因为我正在发出异步调用(针对同一主机,即属于同一连接池)在每个批次大小都高于最大池大小的批次中。当然,解决方案是增加最大池大小。

我想知道的是,在发出较少的较大批量大小(具有较大的最大池大小)的迭代与较大的较小批量大小的迭代(具有较小的池大小)之间的权衡是什么。将池大小扩展到无限大并在一个批处理请求中发出所有异步调用(属于同一池)有什么问题?

requests.adapters HTTPAdapter the settings for the connection pool are likely passed directly down to urllib3's PoolManager

调整 ConnectionPool 的大小以允许更多连接没有问题。但是,您应该考虑一个缺点……主机响应您的请求的能力。根据我的经验,这将是真正的瓶颈。其实参考上面的urllib3link:

However, if you specify block=True then there can be at most maxsize connections open to a particular host. Any new requests will block until a connection is available from the pool. This is a great way to prevent flooding a host with too many connections in multi-threaded applications.