urllib3 connectionpool - 连接池已满,丢弃连接

2022-01-24 00:00:00 python connection pool urllib3

问题描述

看到了

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

意味着我实际上正在丢失数据(因为失去连接)

是否意味着连接被丢弃(因为池已满);但是,当连接池可用时,稍后会重新尝试相同的连接?

mean that I am effectively loosing data (because of lost connection)
OR
Does it mean that connection is dropped (because pool is full); however, the same connection will be re-tried later on when connection pool becomes available?


解决方案

没有数据丢失!

连接被丢弃在请求完成后(因为池已满,如前所述).这意味着这个特定的连接将来不会被重复使用.

The connection is being discarded after the request is completed (because the pool is full, as mentioned). This means that this particular connection is not going to be re-used in the future.

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

Because a urllib3 PoolManager reuses connections, it will limit how many connections are retained per hos to avoid accumulating too many unused sockets. The PoolManager can be configured to avoid creating excess sockets when the pool doesn't have any idle sockets available with PoolManager(..., block=True).

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

If you're relying on concurrency, it could be a good idea to increase the size of the pool (maxsize) to be at least as large as the number of threads you're using, so that each thread effectively gets its own connection.

更多详情:https://urllib3.readthedocs.io/en/latest/advanced-usage.html#customizing-pool-behavior

相关文章