urllib3 连接池 - 连接池已满,正在丢弃连接

urllib3 connectionpool - Connection pool is full, discarding connection

看到

了吗
urllib3.connectionpool WARNING - Connection pool is full, discarding connection

意味着我正在丢失数据(因为失去连接)
或者
这是否意味着连接已断开(因为池已满);但是,当连接池可用时,稍后将重试相同的连接?

没有数据丢失!

请求完成后正在丢弃连接(因为池已满,如前所述)。这意味着将来不会重新使用此特定连接。

因为 urllib3 PoolManager 重用连接,它会限制每个主机 保留 的连接数,以避免累积太多未使用的套接字。 PoolManager 可以配置为避免在池中没有可用的空闲套接字时创建过多的套接字 PoolManager(..., block=True).

如果您依赖并发,最好将池的大小 (maxsize) 增加到至少与您正在使用的线程数,以便每个线程有效地获得自己的连接。

此处有更多详细信息:https://urllib3.readthedocs.io/en/latest/advanced-usage.html#customizing-pool-behavior

根据documentation on Customizing Pool Behavior您的两个解释都不正确:

By default, if a new request is made and there is no free connection in the pool then a new connection will be created. However, this connection will not be saved if more than maxsize connections exist. This means that maxsize does not determine the maximum number of connections that can be open to a particular host, just the maximum number of connections to keep in the pool.

(我的重点)

因此连接没有中止以便稍后重试。根据要求,它们立即生成,并返回了结果。然后,它们完成后,那些“额外的”连接被丢弃,即它们没有保留在池中供以后重用。

例如,如果您的 maxsize 为 10(通过 requests 使用 urllib3 时的默认值),并且您并行启动 50 个请求,则这 50 个连接将在一次,完成后只有 10 个留在池中,而 40 个将被丢弃(并发出警告)。