go: net: DNS resolves slowly
What version of Go are you using (go version)?
go1.8.1 & go1.9
Does this issue reproduce with the latest release?
not found yet
What operating system and processor architecture are you using (go env)?
GOARCH=“amd64” GOBIN=“” GOEXE=“” GOHOSTARCH=“amd64” GOHOSTOS=“linux” GOOS=“linux” GOPATH=“/home/XXX/go” GORACE=“” GOROOT=“/home/XXX/local/go1.9/go” GOTOOLDIR=“/home/XXX/local/go1.9/go/pkg/tool/linux_amd64” GCCGO=“gccgo” CC=“gcc” GOGCCFLAGS=“-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build967902580=/tmp/go-build” CXX=“g++” CGO_ENABLED=“1” CGO_CFLAGS=“-g -O2” CGO_CPPFLAGS=“” CGO_CXXFLAGS=“-g -O2” CGO_FFLAGS=“-g -O2” CGO_LDFLAGS=“-g -O2” PKG_CONFIG=“pkg-config”
What did you do?
when I used httpclient to send post request to a URL, I found it took more time than use python or java in the same environment. go took 6S, python took less than 1S. After analysis and exclusion, I found it spend too much time on DNS resolve. if I replace domain names with the IP, the request take almost as much time as python&java take. One more thing, all above is only for a specified domain, I’m not sure if there’s other special domain name like this cause this problem.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 33 (19 by maintainers)
@nussjustin i used
httptraceto trace the request, the code like this:and get the result :
I believe I’ve found a way to reproduce the issue using a public domain name. The
/etc/resolv.conffile on the Linux machine looked like this when the 10+ second DNS lookup times were happening with Go 1.11 (and not with Go 1.10) with subdomains ending infaa.gov:The last
nameserver 172.19.50.27entry was an old entry that no longer resolved to an actual machine. Public domains likewww.google.comorwww.yahoo.comwere resolving within tens of milliseconds even with this configuration. However, if I add, for example,yahoo.comto thesearchline, now Go 1.11 takes 10+ seconds to resolvesports.yahoo.com(trying allnameserverentries); whereas, Go 1.10 resolves within tens of milliseconds with this configuration (only using the firstnameserverentry). Also,hostanddigboth resolvesports.yahoo.comwith a few milliseconds using this configuration. It appears this configuration causes Go-based DNS lookup on 1.11 to try all nameservers listed in the/etc/resolv.conf; whereas, Go-based DNS lookup on 1.10 and standard command line tools only use the firstnameserverentry.In my service, the net.Resolver stalling 5s+ occurred once every 150 queries. This service is built in go1.11 .
The AAAA reponse alway this: