GO语言:对于许多并发的HTTP连接,MaxIdleConnsPerHost是什么意思?

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

GOlang: MaxIdleConnsPerHost for many concurrent http connections?

问题

在存在100个与同一主机的并发连接的情况下,这些连接可能会在时间上重复出现,将MaxIdleConnsPerHost设置为100是否有意义?

为了避免连接上出现大量无法重用的TIME_WAIT状态,可能的合适值是多少?

英文:

In case of 100 concurrent connections with the same host, which could be repeating in time, would it make sense to set MaxIdleConnsPerHost to 100?

What could be a suitable value in order to avoid a big amount on unreusable TIME_WAIT status on the connection?

答案1

得分: 2

正如我之前提到的,TIME_WAIT在这种情况下不是你需要担心的事情。通常情况下,直到你真正需要担心它之前,它也不是你需要担心的事情,而且一些系统设置通常会在你的代码之外处理这个问题。

如果你的服务非常繁忙,那么尽可能使你的软件更高效可能是最好的选择。如果你对同一主机进行多次重复调用,HTTP1.1的keepalive连接是一种方法。也就是说,对于你的需求来说,100个空闲连接可能是完全可以的;或者它可能超过了远程服务愿意让你保持打开的连接数(除非你也控制这个)。

测量、测试和基准测试,然后确定你需要的容量。

英文:

As I mentioned, TIME_WAIT is't something you shouldn't worry about in this context. It's also usually not something you worry about until you actually need to, and a few systems setting usually take care of that outside of your code.

If your service is very busy, you're going to be best served by making your software as efficient as possible regardless. HTTP1.1 keepalive connections are one way to do this if you make many repeated calls to the same hosts. That said, 100 idle connections might be just fine for what you need; or it might be more than the remote service is willing to let you keep open (unless you control that too).

Measure, test, and benchmark, then figure out what sort of capacity you're going to need.

huangapple
  • 本文由 发表于 2014年3月20日 03:46:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/22516582.html
匿名

发表评论

匿名网友

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

确定