Go(lang): about MaxIdleConnsPerHost in the http client's transport

huangapple go评论95阅读模式
英文:

Go(lang): about MaxIdleConnsPerHost in the http client's transport

问题

如果将MaxIdleConnsPerHost设置为一个很大的数,比如1000,那么打开的连接数仍然取决于其他主机,对吗?我的意思是,只要这些连接没有被其他主机关闭,允许与同一主机建立1000个空闲连接将导致打开1000个连接?

因此,将此值设置为一个很大的数,将导致永远不关闭连接,而是等待其他主机关闭连接?我的理解正确吗?

英文:

In case MaxIdleConnsPerHost is set to a high number, let's say 1000, the number of connections open will still depend on the other host, right? I mean, allowing 1000 idle connections with the same host will result in 1000 connections open as long as these are not closed by the other host?

So, effectively setting this value to a high number, will result in never closing a connection, but waiting for the other host to do it? am I interpreting this correctly?

答案1

得分: 6

你的理解是正确的。MaxIdleConnsPerHost 限制了没有主动处理请求但客户端尚未关闭的连接数量。

对于Web浏览器来说,空闲连接非常有用,因为它们可以在后续的HTTP请求中重复使用与同一服务器的连接。然而,空闲连接对服务器来说是有成本的。它们使用内核资源,你可能会遇到每个进程的限制或内核对打开连接、文件或句柄数量的限制,这可能会导致程序出现意外错误,甚至影响同一台机器上的其他程序。

因此,当将 MaxIdleConnsPerHost 增加到一个较大的数值时要小心。只有在短时间内从相同的客户端看到许多连接时,增加空闲连接才有意义。

英文:

Your understanding is correct. MaxIdleConnsPerHost restricts how many connections there are which are not actively serving requests, but which the client has not closed.

Idle connections are useful for web browsers because they can keep reusing connections for subsequent HTTP requests to the same server. Idle connections have a cost for the server, though. They use kernel resources, and you may run up against per process limits or kernel limits on the number of open connections, files, or handles, which may cause unexpected errors in your program, or even for other programs on the same machine.

As such, be careful when increasing MaxIdleConnsPerHost to a large number. It only makes sense to increase idle connections if you are seeing many connections in a short period from the same clients.

huangapple
  • 本文由 发表于 2014年4月5日 20:47:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/22881090.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定