I would refer you back to the other article I linked to on setting up your host 
name properly.

When I test using the default DNS resolving I can resolve both ‘iMac’ and 
‘iMac.local’ in 2-3 milliseconds without any entry in my /etc/hosts file.  If I 
add the entry ‘iMac.local’ to my /etc/hosts file it still resolves fine.

When I use a invalid hostname, it is 5 seconds - always. It appears it is using 
a CGo/Library path that bypasses the DNS cache.

Note that this differs from the Go DNS resolver (using GODEBUG=netdns=Go) where 
it is only 5 seconds at most the first time, then it is cached for some period 
of time across process restarts, so that subsequent ‘invalid’ queries only take 
a few milliseconds.

> On Feb 23, 2021, at 11:51 AM, Peng Yu <pengyu...@gmail.com> wrote:
> 
>>> I don’t understand why ping does not have the same problem. Ping is not
>>> based on C library?
>>> 
>> 
>> Looking at the source code, the ping command on macOS use gethostbyname2()
>> [1][2], while the Go on macOS use C library through getaddrinfo [3][4].
> 
> If so, I'd consider it as a performance bug of net.Dial() on macOS.
> After all, the following command runs quickly to resolve an IP address
> from a name (suffixed with .local) in /etc/hosts much faster. So
> net.Dial() could (and probably should) just use this (or something
> along this line) on macOS to fix the performance problem.
> 
> net.ResolveIPAddr("ip4", addr)
> 
> -- 
> Regards,
> Peng
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3Dfb_BXwdbcfJzfrMafRhfj6mxzVZ_5udx9yo5iFpWgSw%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/0883DD9C-7F6D-483F-BE1B-F7BDE1E029EB%40ix.netcom.com.

Reply via email to