This is an automated email from the ASF dual-hosted git repository.

achennaka pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 9ede74b8a [java] sync slow DNS resolution threshold with the C++ code
9ede74b8a is described below

commit 9ede74b8a575be4185a73530181e8714a1f1b322
Author: Alexey Serbin <ale...@apache.org>
AuthorDate: Thu Nov 30 12:47:26 2023 -0800

    [java] sync slow DNS resolution threshold with the C++ code
    
    Prior to this patch, the threshold for slow DNS resolution warning
    was set to just 3 ms in the code of the Kudu Java client, which didn't
    make a lot of sense if talking about non-cached DNS queries.
    
    This patch synchronizes the warning threshold with the corresponding
    threshold in the Kudu's C++ code (200 ms), and also doubles the debug
    threshold, bumping up the latter from 0.5 ms to 1 ms.
    
    Change-Id: I8c2b938b2738e1127adfdf834f0e7f0176cf35b7
    Reviewed-on: http://gerrit.cloudera.org:8080/20743
    Tested-by: Alexey Serbin <ale...@apache.org>
    Reviewed-by: Abhishek Chennaka <achenn...@cloudera.com>
---
 .../main/java/org/apache/kudu/util/NetUtil.java    | 28 +++++++++++++++-------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/java/kudu-client/src/main/java/org/apache/kudu/util/NetUtil.java 
b/java/kudu-client/src/main/java/org/apache/kudu/util/NetUtil.java
index 26b10450d..5f40e49ba 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/util/NetUtil.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/util/NetUtil.java
@@ -113,25 +113,37 @@ public class NetUtil {
   /**
    * Gets a hostname or an IP address and returns an array of InetAddresses.
    * <p>
-   * <strong>This method can block</strong> as there is no API for
-   * asynchronous DNS resolution in the JDK.
+   * <strong>This method can block for a long time</strong> if DNS resolution
+   * is slow.
    * @param host the hostname to resolve
    * @return an array of InetAddresses for the given hostname,
    * or {@code null} if the address couldn't be resolved
    */
   public static InetAddress[] getAllInetAddresses(final String host) {
+    // The 'slow DNS resolution' warning threshold is set to be the same as
+    // in HostPort::ResolveAddresses() from src/kudu/util/net/net_util.cc.
+    final long kWarningThresholdNs = 200000000; // 200 ms
+
+    // Once a DNS name is resolved into IP addresses, DNS caching layers of
+    // a contemporary OS makes follow-up resolutions faster. However, when
+    // investigating latencies of relatively fast RPC calls, make it possible
+    // to see in debug logs the exact timing of DNS resolutions that took
+    // over one millisecond.
+    final long kDebugThresholdNs = 1000000;     // 1 ms
+
     final long start = System.nanoTime();
     try {
       InetAddress[] ipAddrs = InetAddress.getAllByName(host);
-      long latency = System.nanoTime() - start;
-      if (latency > 500000/*ns*/ && LOG.isDebugEnabled()) {
-        LOG.debug("Resolved IP of `{}' to {} in {}ns", host, ipAddrs, latency);
-      } else if (latency >= 3000000/*ns*/) {
-        LOG.warn("Slow DNS lookup! Resolved IP of `{}' to {} in {}ns", host, 
ipAddrs, latency);
+      final long elapsedNs = System.nanoTime() - start;
+
+      if (elapsedNs > kDebugThresholdNs && LOG.isDebugEnabled()) {
+        LOG.debug("Resolved '{}' into {} in {}ns", host, ipAddrs, elapsedNs);
+      } else if (elapsedNs > kWarningThresholdNs) {
+        LOG.warn("Slow DNS lookup! Resolved '{}' into {} in {}ns", host, 
ipAddrs, elapsedNs);
       }
       return ipAddrs;
     } catch (UnknownHostException e) {
-      LOG.error("Failed to resolve the IP of `{}' in {}ns", host, 
(System.nanoTime() - start));
+      LOG.error("Failed resolving '{}' into IP addresses in {}ns", host, 
System.nanoTime() - start);
       return null;
     }
   }

Reply via email to