Package com.linkedin.venice.httpclient
Class CachedDnsResolver
- java.lang.Object
-
- com.linkedin.venice.httpclient.CachedDnsResolver
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,org.apache.http.conn.DnsResolver
public class CachedDnsResolver extends java.lang.Object implements org.apache.http.conn.DnsResolver, java.io.Closeable
CachedDnsResolver
caches the dns entries for hosts, which matches the specified host pattern. In the meantime, there is a asynchronous task running to refresh the cached entries periodically. The reason to have this customizedDnsResolver
: 1. If the DNS lookup is slow,AbstractNIOConnPool.lease(Object, Object)
will be blocked by the slow DNS lookup, which will cause a lot of requests being blocked since the slow DNS lookup will grab the per-connection-pool lock until it is done; 2. Here we choose to use a asynchronous task to refresh the cached entries is that the synchronous refresh with TTL will still cause latency spike because of #1;
-
-
Constructor Summary
Constructors Constructor Description CachedDnsResolver(java.lang.String cachedHostPattern, long refreshIntervalInMs, DnsLookupStats stats)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
protected java.util.Optional<java.net.InetAddress[]>
getEntryFromDnsCache(java.lang.String host)
java.net.InetAddress[]
resolve(java.lang.String host)
protected java.net.InetAddress[]
systemGetAllByName(java.lang.String host)
-
-
-
Constructor Detail
-
CachedDnsResolver
public CachedDnsResolver(java.lang.String cachedHostPattern, long refreshIntervalInMs, DnsLookupStats stats)
-
-
Method Detail
-
resolve
public java.net.InetAddress[] resolve(java.lang.String host) throws java.net.UnknownHostException
- Specified by:
resolve
in interfaceorg.apache.http.conn.DnsResolver
- Throws:
java.net.UnknownHostException
-
getEntryFromDnsCache
protected java.util.Optional<java.net.InetAddress[]> getEntryFromDnsCache(java.lang.String host)
-
systemGetAllByName
protected java.net.InetAddress[] systemGetAllByName(java.lang.String host) throws java.net.UnknownHostException
- Throws:
java.net.UnknownHostException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
-