Several months ago I noticed that my text editor (emacs) and IDE (IntelliJ) were taking a really long time to start up. The time appeared to vary based on the DNS servers OS X was using.
I was able to isolate the issue when a project's test suite was running slowly. I found the (higher level) culprit to be a call to
Running the following command in the terminal on OS X 10.10.2, demonstrates the problem:
$ time python -c 'import socket; socket.getfqdn()' python -c 'import socket; socket.getfqdn()' 0.02s user 0.00s system 0% cpu 5.122 total
I traced the code that runs when
socket.getfqdn() is called and the delay is caused by
getaddrinfo(3). I wrote a small program that isolates the problem and
gai_strerror(3) provides this message:
$ time ./hostinfo Hostname: MacBook-Pro.local getaddrinfo: nodename nor servname provided, or not known ./hostinfo 0.00s user 0.00s system 0% cpu 5.101 total
It seems like the delay is waiting for the DNS query to time out. The above results were using Google's public DNS servers. If I use my ISP's DNS servers, however, the time increases to 30 seconds:
$ time python -c 'import socket; socket.getfqdn()' python -c 'import socket; socket.getfqdn()' 0.01s user 0.01s system 0% cpu 30.114 total
(curiously the C program
hostinfo still takes just above 5 seconds)
What is causing this issue? Is my hostname invalid or causing problems?
$ hostname MacBook-Pro.local
This problem doesn't happen on a Macbook Air on the same network.
The major difference I can see is that on the problematic machine, the following DNS confiugration is listed:
$ scutil --dns DNS configuration resolver #1 search domain : Home nameserver : 18.104.22.168 nameserver : 22.214.171.124 flags : Request A records reach : Reachable DNS configuration (for scoped queries) resolver #1 search domain : Home nameserver : 126.96.36.199 nameserver : 188.8.131.52 if_index : 4 (en0) flags : Scoped, Request A records reach : Reachable
On the Macbook Air, several extra entries are included that relate to mDNS. For example:
resolver #2 domain : local options : mdns timeout : 5 flags : Request A records order : 300000
This seems to be significant. Interestingly, the timeout listed above is about the same as the runtimes above.
I should note that I'm connected to the internet using WiFi and the problem only exists when trying to resolve my computer's host name.