Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread robert engels
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 fi

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Peng Yu
>> 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

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Robert Engels
Nice work. > On Feb 23, 2021, at 10:16 AM, Shulhan wrote: > >  >> On 23 Feb 2021, at 12.40, Peng Yu 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()

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Shulhan
> On 23 Feb 2021, at 12.40, Peng Yu 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].

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Robert Engels
I looked into it more. You can use GODEBUG to configure to use the Go dns resolver - but even if you don’t there is a significant Go layer to Dial - it is not a simple pass through to the C call. > On Feb 23, 2021, at 8:54 AM, Kevin Chadwick wrote: > > On February 23, 2021 2:46:20 PM UTC, Ro

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Kevin Chadwick
On February 23, 2021 2:46:20 PM UTC, Robert Engels wrote: >I am not 100% certain but the build statement at the top of the Unix >dns client specified Darwin. I would read the Go issues I linked to in >the code snippet. I believe it varies. Android has no universal textual interface - /etc/reso

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Robert Engels
I am not 100% certain but the build statement at the top of the Unix dns client specified Darwin. I would read the Go issues I linked to in the code snippet. > On Feb 23, 2021, at 8:29 AM, Peng Yu wrote: > > Hi Robert, > > Ian Lance Taylor said the exact opposite. "On Darwin I believe that b

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Peng Yu
Hi Robert, Ian Lance Taylor said the exact opposite. "On Darwin I believe that by default we pass DNS lookups to the C library." (I assume "we" means Go developers.) Are you correct or Ian is correct? On Tue, Feb 23, 2021 at 8:14 AM Robert Engels wrote: > > As I pointed out, Go does not use the

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Kevin Chadwick
On February 23, 2021 1:57:07 PM UTC, Peng Yu wrote: >This does not answer the question why net.Dial can not be made with >the same behavior as ping on MacOSX. If the C library behaves >differently on MacOSX and Linux, then the C library should not be >relied on in this case. I just want to use /et

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Robert Engels
As I pointed out, Go does not use the C library. > On Feb 23, 2021, at 7:57 AM, Peng Yu wrote: > > This does not answer the question why net.Dial can not be made with > the same behavior as ping on MacOSX. If the C library behaves > differently on MacOSX and Linux, then the C library should no

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Peng Yu
This does not answer the question why net.Dial can not be made with the same behavior as ping on MacOSX. If the C library behaves differently on MacOSX and Linux, then the C library should not be relied on in this case. I just want to use /etc/hosts but not resolve.conf. On 2/22/21, robert engels

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread robert engels
There is also this note in the /etc/resolv.conf file: # # macOS Notice # # This file is not consulted for DNS hostname resolution, address # resolution, or the DNS query routing mechanism used by most # processes on this system. but the Go DNS client uses resolv.conf for its configuration - that

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread robert engels
Still, if you follow that article I referred you to it may fix your issue - as the resolv.conf is auto-generated on OSX and includes hostname mappings. > On Feb 22, 2021, at 11:48 PM, robert engels wrote: > > It looks like the Go runtime implements its own DNS client on *unix platforms > inclu

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread robert engels
It looks like the Go runtime implements its own DNS client on *unix platforms including OSX. > On Feb 22, 2021, at 11:40 PM, Peng Yu wrote: > > I don’t understand why ping does not have the same problem. Ping is not based > on C library? > > On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread Peng Yu
I don’t understand why ping does not have the same problem. Ping is not based on C library? On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor wrote: > On Mon, Feb 22, 2021 at 9:11 PM Peng Yu wrote: > > > > I tried 1.16. > > > > $ go version > > go version go1.16 darwin/amd64 > > > > The problem

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread robert engels
This https://apple.stackexchange.com/questions/175320/why-is-my-hostname-resolution-taking-so-long may help you. > On Feb 22, 2021, at 11:20 PM, Ian Lance Taylor wrote: > > On Mon, Feb 22, 2021 at

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread Ian Lance Taylor
On Mon, Feb 22, 2021 at 9:11 PM Peng Yu wrote: > > I tried 1.16. > > $ go version > go version go1.16 darwin/amd64 > > The problem still exists. When I change mymachine.local to > mymachine_local, the problem is gone. So somehow, this is related to > host resolution? It might try to DNS lookup the

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread Shulhan
> On 23 Feb 2021, at 12.11, Peng Yu wrote: > > I tried 1.16. > > $ go version > go version go1.16 darwin/amd64 > > The problem still exists. When I change mymachine.local to > mymachine_local, the problem is gone. So somehow, this is related to > host resolution? It might try to DNS lookup t

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread Peng Yu
I tried 1.16. $ go version go version go1.16 darwin/amd64 The problem still exists. When I change mymachine.local to mymachine_local, the problem is gone. So somehow, this is related to host resolution? It might try to DNS lookup the hostname, when it can not find it via DNS then it look up in /e

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread Ian Lance Taylor
On Mon, Feb 22, 2021 at 12:22 PM Peng Yu wrote: > > I run the following go program using net.Dial(). Depending on whether > I specify a local hostname (defined in /etc/hosts) or an IP. I get > very different runtimes. > > But `ping mymachine.local` resolves the hostname to an IP address > instanta

[go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread Peng Yu
Hi, I run the following go program using net.Dial(). Depending on whether I specify a local hostname (defined in /etc/hosts) or an IP. I get very different runtimes. But `ping mymachine.local` resolves the hostname to an IP address instantaneously. So the two calls of the go program should have t