http request takes time if i use domain name instead of ip address

时间:2017-06-15 10:32:24

标签: ruby-on-rails http nginx dns get

I am sending an HTTP GET request in postman.

the first request is using IP address i.e.

get 52.66.166.14

which takes around 70ms to complete.

The second request is using domain name, i.e.

get dev.iotrek.in

which takes around 450ms to complete.

What is the reason fo this to occur? this delay that I am getting in apis.

My server is running nginx-passenger. My backend is ruby on rails.

1 个答案:

答案 0 :(得分:0)

这种差异可能等于您对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。