Golang http客户端为什么有MaxConnsPerHost却没有MaxConns
In Golang http client, why there is MaxConnsPerHost but no MaxConns
我在 Go http 包中看到:
MaxIdleConnsPerHost 整数
但是我没有看到整个 http 客户端的任何 MaxConns,为什么?
如果我只限制 MaxIdleConns(针对整个客户端)是否有可能超过此活动连接限制? (我假设答案是简单的是,但这只是理论上的吗?)
来自文档:
// MaxIdleConnsPerHost, if non-zero, controls the maximum idle
// (keep-alive) connections to keep per-host. If zero,
// DefaultMaxIdleConnsPerHost is used.
MaxIdleConnsPerHost int
// MaxConnsPerHost optionally limits the total number of
// connections per host, including connections in the dialing,
// active, and idle states. On limit violation, dials will block.
//
// Zero means no limit.
MaxConnsPerHost int
I do not see any MaxConns for the whole http client, why?
因为有none。如果你不想和那个客户端发出超过n个并发请求,那就不要这样做(如果客户端会限制,那将是一个主要的皮塔饼)。
If I only limit MaxIdleConns (per the whole client) is it possible to have more than this limit of active connections?
是的。 MaxIdlConns
限制空闲连接而不是非空闲连接。
我在 Go http 包中看到:
MaxIdleConnsPerHost 整数
但是我没有看到整个 http 客户端的任何 MaxConns,为什么?
如果我只限制 MaxIdleConns(针对整个客户端)是否有可能超过此活动连接限制? (我假设答案是简单的是,但这只是理论上的吗?)
来自文档:
// MaxIdleConnsPerHost, if non-zero, controls the maximum idle
// (keep-alive) connections to keep per-host. If zero,
// DefaultMaxIdleConnsPerHost is used.
MaxIdleConnsPerHost int
// MaxConnsPerHost optionally limits the total number of
// connections per host, including connections in the dialing,
// active, and idle states. On limit violation, dials will block.
//
// Zero means no limit.
MaxConnsPerHost int
I do not see any MaxConns for the whole http client, why?
因为有none。如果你不想和那个客户端发出超过n个并发请求,那就不要这样做(如果客户端会限制,那将是一个主要的皮塔饼)。
If I only limit MaxIdleConns (per the whole client) is it possible to have more than this limit of active connections?
是的。 MaxIdlConns
限制空闲连接而不是非空闲连接。