在Golang的HTTP客户端中,MaxConnsPerHost和MaxIdleConnsPerHost中的Host是什么意思?

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

In Golang http client, what does Host mean in MaxConnsPerHost and MaxIdleConnsPerHost?

问题

在GO HTTP包中的MaxConnsPerHost和MaxIdleConnsPerHost中,"Host"是一个域名(例如yahoo.com)还是一个IP地址?"Host"的实际含义将影响我对连接池的设置。

英文:

In MaxConnsPerHost and MaxIdleConnsPerHost in GO HTTP package, is "Host" a domain(i.e., yahoo.com) or an IP address? The actual meaning of "Host" will affect my settings for the connection pool.

答案1

得分: 1

主机是URL的以下部分:

http://THIS.IS.THE.HOST/path/to/endpoint
       ^^^^^^^^^^^^^^^^

URL中下划线部分是主机。主机可以是域名或IP地址,这取决于使用的URL。请注意,它不依赖于响应请求的服务器。

例如,在以下URL中:

http://127.0.0.1/api/list-all

主机是127.0.0.1。但在以下URL中:

http://example.com/api/list-all

主机是example.com

如果你有两个配置如下的服务器:

                     ┌───── HTTP Server 1 (10.20.30.40)
                     │        ├ www.foo.com (default)
                     │        └	www.bar.com
                     │
  DNS Load ──────────┤
  Balancer           │
                     └───── HTTP Server 2 (11.22.33.44)
                              └ www.bar.com (default)

那么http://www.bar.com被认为是相同的主机,即使它由两个不同的IP地址提供服务(10.20.30.4011.22.33.44 - 注意:DNS负载均衡器不处理HTTP请求,而是处理DNS请求,并将不同的IP地址发送给不同的客户端以进行负载均衡)。

然而,11.22.33.44www.bar.com被认为是两个不同的主机,即使它们提供完全相同的内容。

类似地,www.foo.comwww.bar.com10.20.30.40被认为是3个不同的主机,即使它们都由同一个服务器和同一个IP地址提供服务(如果www.bar.com的负载均衡器解析为10.20.30.40)。

英文:

The host is the following part of a URL:

http://THIS.IS.THE.HOST/path/to/endpoint
       ^^^^^^^^^^^^^^^^

The underlined part of the URL is the host. The host can either be a domain name or an IP address - it depends on the URL you use. Note that it does not depend on the server answering the request.

For example, in the following:

http://127.0.0.1/api/list-all

The host is 127.0.0.1. But in the following:

http://example.com/api/list-all

The host is example.com.

If you have two servers configured like the following:

                     ┌───── HTTP Server 1 (10.20.30.40)
                     │        ├ www.foo.com (default)
                     │        └	www.bar.com
                     │
  DNS Load ──────────┤
  Balancer           │
                     └───── HTTP Server 2 (11.22.33.44)
                              └ www.bar.com (default)

Then http://www.bar.com is considered the same host even though it is served by two different IP addresses (10.20.30.40 and 11.22.33.44 - note: DNS load balancers do not handle HTTP request instead it handles DNS requests and will send different IP addresses to different clients to load-balance)

However 11.22.33.44 and www.bar.com are considered two different hosts even though both serve the exact same content.

Similarly www.foo.com and www.bar.com and 10.20.30.40 are considered 3 different hosts even though they are all served by the same server and same IP address (if the load balancer for www.bar.com resolve to 10.20.30.40).

答案2

得分: 0

http://www.example.com/abc/def中,“Host”是www.example.com

主机可能对应多个IP地址。这是正常的。

英文:

“Host” in http://www.example.com/abc/def is www.example.com.

The host may correspond to multiple IP addresses. This is normal.

答案3

得分: 0

“主机”一词指的是请求URL的主机部分。该术语不指代主机解析到的IP地址。

英文:

The term “host” refers to the host part of the request URL. The term does not refer to the IP addresses that the host resolves to.

huangapple
  • 本文由 发表于 2022年7月4日 06:41:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/72850372.html
匿名

发表评论

匿名网友

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

确定