Go会缓存DNS查找吗? [英] Does Go cache DNS lookups?

查看:85
本文介绍了Go会缓存DNS查找吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个测试搜寻器,想知道Go(golang)是否缓存DNS查询。我没有在 dnsclient 中看到有关缓存的任何信息。添加到任何搜寻器以防止大量额外的DNS查询似乎很重要。

I am building a test crawler and wanted to know if Go (golang) caches DNS queries. I don't see anything about caching in the dnsclient. This seems like an important thing to add to any crawler to prevent lots of extra DNS queries.

Go(1.4+)是否缓存DNS查找?

如果没有, debian / ubuntu / linux,windows或darwin / OSX可以在Go上进行网络级缓存吗?

If not, does debian/ubuntu/linux, windows, or darwin/OSX do any caching at the network level Go benefits from?

推荐答案

您的问题的答案是否定的。 std lib解析器中没有内置的dns缓存。有帮助吗?也许在某些情况下。我们的组织在每个服务器上运行本地dns缓存,并将resolv.conf指向该服务器。因此,使用该语言进行缓存不一定会对我们有太大帮助。

The answer to your question is no. There is no built-in dns caching in the std lib resolver. Would it be helpful? Maybe in some cases. Our org runs a local dns cache on each server and points resolv.conf there. So it wouldn't necessarily help us much to have caching in the language.

有些解决方案可以为您提供帮助。 此软件包似乎有一个很好的解决方案。从他们的自述文件中,您甚至可以执行以下操作:

There are some solutions that could help you. This package seems to have a pretty good solution. From the snippet in their readme you could even do:

http.DefaultClient.Transport = &http.Transport {
  MaxIdleConnsPerHost: 64,
  Dial: func(network string, address string) (net.Conn, error) {
    separator := strings.LastIndex(address, ":")
    ip, _ := dnscache.FetchString(address[:separator])
    return net.Dial("tcp", ip + address[separator:])
  },
}

http.Get 和朋友的所有http请求启用它

To enable it for all http requests from http.Get and friends.

这篇关于Go会缓存DNS查找吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆