Golang http客户端中,为什么有MaxConnsPerHost却没有MaxConns

gal*_*ben 5 connection-pooling http go

  1. 我在 Go http 包中看到:

    MaxIdleConnsPerHost int 整数

    但我没有看到整个 http 客户端有任何 MaxConns,为什么?

  2. 如果我只限制 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
Run Code Online (Sandbox Code Playgroud)

Vol*_*ker 3

我没有看到整个 http 客户端有任何 MaxConns,为什么?

因为没有。如果您不想与该客户端发出超过 n 个并发请求,那就不要这样做(如果客户端会限制,那么使用它将是一个主要的皮塔饼)。

如果我只限制 MaxIdleConns(每个整个客户端),是否可以有超过此限制的活动连接?

是的。MaxIdlConns限制空闲连接而不是非空闲连接。