getaddrinfo 问题

发布于 2024-12-09 02:25:35 字数 294 浏览 0 评论 0原文

我目前正在尝试编写自己的 HTTP 代理。我的代码可以工作,但我尝试使用 ApacheBench 对它进行压力测试,发现时不时地我会收到如下消息:

“getaddrinfo:提供了节点名或服务名,或者主机 en.wikipedia.org 服务 80 未知”

我无法弄清楚为什么这个函数调用在主机名和端口传递的地方会失败。

我在网上寻找了解决此问题的不同方法,但没有发现任何有用的方法。

有人有什么想法吗?

编辑 通过在我的应用程序中实现 DNS 缓存系统解决了这个问题。

I am currently playing around with writing my own HTTP proxy. I have the code working but I attempted to stress test it with ApacheBench and found that every now and again I get a message such as follows:

"getaddrinfo: nodename nor servname provided, or not known for host en.wikipedia.org service 80"

I can not work out why this function call should fail on where the hostname and port are passed.

I have looked online for different ways to solve this and have found nothing useful.

Does anyone have any ideas?

edit
Solved this problem by implementing a DNS caching system within my application.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞取 2024-12-16 02:25:35

也许您的解决方案堆栈中的某些内容无法承受您正在进行的查询量?

您必须从 /etc/nsswitch.conf 开始,并查看系统上如何解析查询。在某些时候,您最终会访问本地 DNS 缓存,如果同时有太多查询,也可能会超时。

您可能会发现需要在代理中运行 DNS 缓存(例如,Squid 就是如此)或在本地使用 lwresd 等运行 DNS 缓存。

Maybe something in your resolution stack couldn't take the volume of queries you were making?

You'd have to start with /etc/nsswitch.conf, and see how queries are resolved on your system. At some point, you'll eventually get to your local DNS cache, which may also time out if it has too many queries at once.

You may find that you need to run a DNS cache either in your proxy (Squid does, for example) or locally with e.g., lwresd.

内心旳酸楚 2024-12-16 02:25:35

我建议使用异步 DNS 解析库,例如 C-ares。否则,您很快就会发现标准解析将如何降低您的性能,因为它会阻塞。

I'd recommend using an asynchronous DNS resolving library like C-ares. Otherwise you will discover quickly how standard resolving is going to kill your performance, since it will block.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文