问题描述
在通过一个Modem / ISP连接时,我曾经在我的Ubuntu机器上进行非常慢的DNS查找。我按照说明(例如)使用持久的DNS缓存,所以我不会重复DNS查找,一切都变得更快。但是,我注意到,当拉/推回放货时,即使转移非常小的变化也是很慢的。更深入地,我发现所有的时间都是由 _socket.getaddrinfo
,即DNS查找。为什么即使所有Web浏览器都使用 /etc/pdnsd.conf
中的信息来使用旧的dns查找,python套接字也不会。如何使用缓存查找?
更新
它可能也是因为尝试获取ipv4和ipv6地址,以及只有在找不到ipv6地址后才返回答案。我不知道如何检查,即是否延迟是由于ipv6,非持久性或两者。
更新 / p>
它可能与ipv6请求有关,如答案,一旦我有机会就必须检查。
Pythons socket.getaddrinfo()使用操作系统的getaddrinfo()(在libc上)。 - 这与Python 在所有无关。如果pdns已经配置为在分辨率链中,则不同的分辨率速度根据不同的请求而生根。 - 仔细查看哪个确实 getaddrinfo()请求是快速的,哪个速度很慢。
I used to have very slow DNS lookups on my Ubuntu machine when connecting through one Modem/ISP. I followed instructions (such as those here) to use persistent DNS caching so I don't do repeated DNS look ups, and everything became much faster. However, I noticed that when pulling/pushing repos on mercurial, it was painfully slow to even transfer very small changes. Looking deeper, I found that all the time was taken by _socket.getaddrinfo
, i.e., DNS lookups. Why is it that even though all web browsers use the info in /etc/pdnsd.conf
to use old dns lookups, pythons sockets do not. How can I get mercurial to use cached lookups?
Update
It might also be because getaddrinfo tries to get both ipv4 and ipv6 addresses, and only returns the answer after it fails to find the ipv6 address. I am not sure how to check this though, i.e., whether the delay is due to ipv6, non-persistence or both.
Update
It might be related to ipv6 requests, as suggested in the answer here, I will have to check that once I get a chance.
Pythons socket.getaddrinfo() uses the OS’s getaddrinfo() (over libc). – This has nothing to do with Python at all. If pdns is already configured to be in the resolution-chain, then different resolution-speeds are rooted by different requests. – Look more closely at which exact getaddrinfo() requests are fast, which are slow.
这篇关于Python的socket.getaddrinfo / mercurial不使用持久性DNS缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!