从getaddrinfo响应缓慢 [英] Slow response from getaddrinfo

查看:1307
本文介绍了从getaddrinfo响应缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用getaddrinfo在Windows上从C ++进行DNS查询。我曾经使用Windows API DnsQuery和工作正常,但是当我添加IPv6支持我的软件,我切换到getaddrinfo。从那时起,我看到了以下内容:



我的问题是,有些时候getaddrinfo需要很长时间才能完成。来自getaddrinfo的典型响应只需要几毫秒,但是大约1次超过10000,它需要更长的时间,在某些情况下大约15秒,但是有几种情况需要几分钟。



我在服务器上运行Wireshark并分析了我的应用程序调试日志,并看到了以下内容:




  • 函数getaddrinfo。

  • 15秒后,我的计算机查询DNS服务器。

  • 几毫秒后, / li>


这里奇怪的是,实际DNS查询只需要十分之一秒,但getaddrinfo实际执行的时间要长得多。



很多用户都报告了这个问题,因此它不是我的机器所特有的。





    $ getaddrinfo做的不是联系DNS服务器吗?



    < b $ b
  • 几个地址发生了问题。如果我尝试使用这些地址重现问题,则不会发生此问题。

  • 我做了一些蠢事。每次DNS查询时,etc / services都会被解析。然而,这并不能解释几分钟的延迟。 (感谢D.Shawley)



编辑2




  • 我的软件进行的一种类型的DNS查询是反垃圾邮件DNSBL查询。来自一个用户的日志显示,ip.address1.example.com的查找总是似乎需要2039秒,而对于another.ip.address.example.com的查找总是精确为1324秒。后一天,这些地址的查找就好了。起初,我认为DNS BL作者在他们身边放了一些超时。但是如果这是核心问题,getaddrinfo应该早点超时了。


解决方案

执行DNS缓存的本地守护程序。您对getaddrinfo()的调用被路由到该守护程序,这可能是在向DNS服务器提交查询之前检查其缓存。



请参阅 Windows知识库文章318803 有关禁用缓存的详情。





对我来说,就好像Windows Server 2003实例没有为IPv6正确配置。一旦IPv6查找超时,它将回退到IPv4。可能包含以下内容的知识库文章:





不幸的是,我无法访问任何Windows服务器,因此我无法自己测试/复制。 >

I'm using getaddrinfo to do DNS queries from C++ on Windows. I used to use the Windows API DnsQuery and that worked fine, but when adding IPv6 support to my software I switched to getaddrinfo. Since then, I've seen the following:

My problem is that some times getaddrinfo take very long time to complete. The typical response from getaddrinfo takes just a few milliseconds, but roughly 1 time out of 10000, it takes longer time, in some cases around 15 seconds but there's been several cases when it takes several minutes.

I've run Wireshark on the server and analyzed my applications debug logs and see the following:

  • I call the function getaddrinfo.
  • 15 seconds later, my machine queries the DNS server.
  • Some milliseconds later, I get the response from the DNS server.

The weird thing here is that the actual DNS query only takes a tenth of a second, but the time getaddrinfo actually executes is much longer.

The problem has been reported by many users, so it's not something specific to my machine.

So what does getaddrinfo do more than contact the DNS server?

Edit:

  • The problem has occurred with several addresses. If I try to reproduce the problem using these addresses, the problem does not occur.
  • I have done something stupid. Upon every DNS query, the etc/services is parsed. However, that doesn't explain a delay on several minutes. (thanks D.Shawley)

Edit 2

  • One type of DNS queries made by my software is anti-spam DNSBL queries. The log from one user showed me that the lookup for ip.address1.example.com always seemed to take exactly 2039 seconds, while the lookup for another.ip.address.example.com always took exactly 1324 seconds. The day after that, the lookups for those addresses were just fine. At first I thought that the DNS BL authors had put some kind of timeout on their side. But if this was the core problem, getaddrinfo should have timed out earlier?

解决方案

Windows has a local daemon that does DNS caching. Your call to getaddrinfo() is getting routed to that daemon, which presumably is checking its cache before submitting the query to your DNS server.

See Windows Knowledge Base article 318803 for more information on disabling the cache.

[Edited]

It sounds to me as though your Windows Server 2003 instance is not configured correctly for IPv6. Once the IPv6 lookups timeout, it will fall back to IPv4. Knowledge Base articles that might help include:

Unfortunately, I don't have access to any Windows Servers, so I can't test/replicate this myself.

这篇关于从getaddrinfo响应缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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