简体   繁体   English

如何解决 Vertx 阻塞 DNS 问题

[英]How to solve Vertx blocking DNS issue

TL;DR: is it possible to overcome blocking DNS issues with Vertx? TL;DR:是否有可能克服 Vertx 的 DNS 阻塞问题? Preferably with Vertx HttpClient?最好使用 Vertx HttpClient?

I'm trying to use Vertx to scrape some URLs with different hosts.我正在尝试使用 Vertx 来抓取不同主机的一些 URL。 I'm currently using Vertx HttpClient to do so, I've recently encountered an issue with a blocking DNS call which sometimes blocks my HttpClient requests (and therefore also blocking the event loop).我目前正在使用 Vertx HttpClient 来执行此操作,我最近遇到了阻塞 DNS 调用的问题,该调用有时会阻塞我的 HttpClient 请求(因此也会阻塞事件循环)。 This issue is described here .此处描述此问题。

I can't use a blocking http client in an "executeBlocking" function since I went for the Vertx solution because it is asynchronous and should be able to handle the loads I'm expecting.我无法在“executeBlocking”函数中使用阻塞 http 客户端,因为我选择了 Vertx 解决方案,因为它是异步的,应该能够处理我期望的负载。 Also I can't resolve the IP address myself because it only solves it for a specific host while I'm trying to fetch many different hosts此外,我自己无法解析 IP 地址,因为它只能在我尝试获取许多不同主机时为特定主机解析它

So my question is: is there any (relatively) elegant solution to this issue that doesn't require me to wait for future Netty versions?所以我的问题是:是否有任何(相对)优雅的解决方案来解决这个问题,不需要我等待未来的 Netty 版本? Preferably something that uses the native Vertx HttpClient.最好是使用本机 Vertx HttpClient 的东西。

Thanks in advance提前致谢

其他选项是通过将-Dvertx.disableDnsResolver添加到命令行来禁用dns 解析器。

Ok so after digging about this issue for several days I found several possible solutions to this issue.好吧,在研究这个问题几天后,我找到了几个可能的解决方案。 I hope this might help someone我希望这可以帮助某人

These are the possible solutions这些是可能的解决方案

  1. Programmatically solving the DNS issue using an executeBlock - this requires first "fixing" the DNS issue using vertx.executeBlocking with a future handler and only when the handler is invoked invoking the actual HTTP client code.使用 executeBlock 以编程方式解决 DNS 问题 - 这需要首先使用 vertx.executeBlocking 和未来处理程序“修复”DNS 问题,并且仅当处理程序被调用以调用实际的 HTTP 客户端代码时。 Some possible optimizations here might be:这里的一些可能的优化可能是:
    • Saving an in memory map of all the hosts that the DNS already resolved and if a URL with a resolved host arrives just scrap it asynchronously.保存 DNS 已经解析的所有主机的内存映射,如果带有解析主机的 URL 到达,则异步废弃它。
    • Setting ordered to false in the executeBlocking statement (if you really don't care about ordering) as it can improve the performance of that code在executeBlocking 语句中将ordered 设置为false(如果您真的不关心排序),因为它可以提高该代码的性能
  2. Waiting for Netty 4.1 to come out.等待 Netty 4.1 出来。 I don't know exactly when it's going to happen but I obviously could not wait for it我不知道它什么时候会发生,但我显然等不及了
  3. Do nothing about blocking the event loop.什么都不做阻止事件循环。 This means the program will be sluggish until the DNS server starts getting cache hits.这意味着程序将缓慢直到 DNS 服务器开始获得缓存命中。 If you can accept some sluggishness, that just might be a good fit如果你能接受一些迟钝,那可能是一个很好的选择

All of these solutions are from the Vertx mailing list.所有这些解决方案都来自 Vertx 邮件列表。 You can see the full correspondence here (including some code examples)您可以在此处查看完整的对应关系(包括一些代码示例)

Currently I'm running the program in a cluster and I didn't encounter this issue on it.目前我正在集群中运行该程序,我没有遇到这个问题。 If I will later need to solve this I will probably aim for the 1st solution (unless Netty 4.1 is released by then)如果我以后需要解决这个问题,我可能会瞄准第一个解决方案(除非那时 Netty 4.1 发布)

I hope I got all the solutions right, if someone sees this and has better ideas or corrections I'll highly appreciate it我希望我的所有解决方案都是正确的,如果有人看到这个并且有更好的想法或更正,我将不胜感激

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM