在Golang http客户端中,为什么有MaxConnsPerHost但没有MaxConns
我在Go http包中看到: MaxIdleConnsPerHost int 但是我没有看到任何适用于整个http客户端的MaxConn,为什么在Golang http客户端中,为什么有MaxConnsPerHost但没有MaxConns,http,go,connection-pooling,Http,Go,Connection Pooling,我在Go http包中看到: MaxIdleConnsPerHost int 但是我没有看到任何适用于整个http客户端的MaxConn,为什么 如果我只限制maxidlecons(每个客户端),那么活动连接是否可能超过此限制?(我想答案很简单,是的,但这仅仅是道德问题吗?) 从文档中: // MaxIdleConnsPerHost, if non-zero, controls the maximum idle // (keep-alive) connections to keep per-ho
// 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
我没有看到任何适用于整个http客户端的MaxConn,为什么
因为没有。如果您不想与该客户机并发请求超过n个,就不要这样做(如果客户机会限制,那么这将是一个主要的pita使用)
如果我只限制maxidlecons(每个客户端),那么活动连接是否可能超过此限制
对
maxidconns
限制空闲连接,而不是非空闲连接。感谢您的回复。当我问为什么时,我的意思是为什么有一个,而不是为什么我找不到它:-)我认为每个客户都有一个限制是有道理的,可能有一些合法的情况下,你希望这个限制来自客户,而不是自己编码这个限制。我猜围棋小组不同意:-)我假设你对“我假设答案是简单的是,但这仅仅是道德上的吗?”-的回答是简单的是。再次感谢您的回复。MaxConns
会做什么您自己无法轻松做到的事情?我并不是说自己不可能做到这一点,但例如,一个应用程序由多个从不同供应商检索数据的处理程序共享http连接。我不想使机器的网络过载。我可以用很多其他的方法来解决这个问题,但是在http客户机上有一个简单的参数就好了。我想对于MaxConnsPerHost也可以问同样的问题。