Discussion:
Advantages of using DNSResolver
Guru Prashanth Thanakodi
2017-11-03 17:11:58 UTC
Permalink
Hi
I saw that connectionManager constructor is taking DNSresolver as
parameter . There are two types of DNSresolver namely
SystemDefaultDNSResolver and InMemoryDNSresolver. When does Apache
httpClient uses these class? If my request url has IPinstead of hostname
will this DNSresolver class still be used?Do I get optimization if I load
the InetAddress once and reuse them?

Thanks,
Guru
Bindul Bhowmik
2017-11-04 22:29:05 UTC
Permalink
On Fri, Nov 3, 2017 at 10:11 AM, Guru Prashanth Thanakodi
Post by Guru Prashanth Thanakodi
Hi
I saw that connectionManager constructor is taking DNSresolver as
parameter . There are two types of DNSresolver namely
SystemDefaultDNSResolver and InMemoryDNSresolver. When does Apache
httpClient uses these class? If my request url has IPinstead of hostname
will this DNSresolver class still be used?Do I get optimization if I load
the InetAddress once and reuse them?
HttpClient uses the SytemDefaultDNSResolver by default. If you need to
customize your dns lookups, you can of course create your own
DNSResolver or use the InMemoryDNSResolver. The
SystemDefaultDNSResolver uses the underlying JRE DNS resolver, which
provides caching in most implementations. Someone with deeper
information into the code can correct me, but as far as I understand
even if you use an IP address, the DNSResolver will be called, but the
method the system default DNS resolver calls -
InetAddress.getAllByName [1] knows if the value passed is an IP
address rather than a hostname, and actually does not do any lookup.

You can of course do pro-active or cache backed DNS resolution and
hook in your own implementation, and again I do not know the details
of your implementation, but you may be missing out on an advantage of
the DNS system - for hosts to be able to move or even provide load
balancing.
Post by Guru Prashanth Thanakodi
Thanks,
Guru
Regards,
Bindul


[1] https://docs.oracle.com/javase/8/docs/api/java/net/InetAddress.html#getAllByName-java.lang.String-

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Loading...