You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Guru Prashanth Thanakodi <tg...@gmail.com> on 2017/11/03 17:11:58 UTC

Advantages of using DNSResolver

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

Re: Advantages of using DNSResolver

Posted by Bindul Bhowmik <bi...@gmail.com>.
On Fri, Nov 3, 2017 at 10:11 AM, Guru Prashanth Thanakodi
<tg...@gmail.com> wrote:
> 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.

>
> 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-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org