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

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

问题描述

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

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:

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

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.

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

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


  • 我打电话给函数getaddrinfo。

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

  • 稍后几秒钟,我收到DNS服务器的响应。 / li>
  • 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.

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

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.

那么getaddrinfo做的不只是联系DNS服务器?

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

编辑:


  • 问题出现在s多个地址如果我尝试使用这些地址重现问题,则不会出现问题。

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

编辑2


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

推荐答案

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

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.

请参阅 Windows知识库文章318803 有关禁用缓存的更多信息。

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

[已编辑]

听起来好像您的Windows Server 2003实例未正确配置IPv6。一旦IPv6查找超时,它将返回到IPv4。知识库文章可能有助于:

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:

  • Windows Server 2003 Deployment Guide >>> Configuring DNS for IPv6/IPv4 Coexistence
  • TechNet Library >>> Internet Protocol Version 6
  • TechNet Library >>> Using Windows Tools to Obtain IPv6 Configuration Information

不幸的是,我无法访问任何Windows Server,所以我无法自己测试/复制。

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

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

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