如果我使用域名而不是 IP 地址,HTTP 请求需要时间



我正在邮递员中发送HTTP GET请求。

第一个请求是使用 IP 地址,即

get 52.66.166.14

大约需要 70 毫秒才能完成。

第二个请求是使用域名,即

get dev.iotrek.in

大约需要 450 毫秒才能完成。

发生这种情况的原因是什么? 我在 API 中得到的这种延迟。

我的服务器正在运行nginx-passenger。我的后端是轨道上的红宝石。

这种差异可能相当于您到 DNS 服务器的延迟。

例如,以下是使用我的 ISP DNS 的请求:

$ curl --silent --output /dev/null example.com -w %{time_connect}:%{time_starttransfer}:%{time_total}
0.142:0.252:0.252

以下是来自另一个大陆的 DNS 请求:

$ curl --silent --output /dev/null example.com -w %{time_connect}:%{time_starttransfer}:%{time_total}
0.414:0.525:0.525

请注意,time_connect是完全不同的。考虑使用地理位置更适合您的 DNS。

最新更新