Package com.linkedin.venice.httpclient
Class CachedDnsResolver
java.lang.Object
com.linkedin.venice.httpclient.CachedDnsResolver
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.http.conn.DnsResolver
public class CachedDnsResolver
extends Object
implements org.apache.http.conn.DnsResolver, 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 customized DnsResolver:
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
ConstructorsConstructorDescriptionCachedDnsResolver(String cachedHostPattern, long refreshIntervalInMs, DnsLookupStats stats) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected Optional<InetAddress[]>getEntryFromDnsCache(String host) protected InetAddress[]systemGetAllByName(String host)
-
Constructor Details
-
CachedDnsResolver
-
-
Method Details
-
resolve
- Specified by:
resolvein interfaceorg.apache.http.conn.DnsResolver- Throws:
UnknownHostException
-
getEntryFromDnsCache
-
systemGetAllByName
- Throws:
UnknownHostException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-