Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getCanonicalHostName is very slow

InetAddress.getByName(ipAddress).getLocalHost().getCanonicalHostName();

The above line takes around 10seconds to execute.

I added the IP and hostname in etc\hosts file and still there is no change.

How does getCanonicalHostName work? Can I get the implementation of that method?

How do I increase the efficiency of this line of code?

like image 436
Hulk Man Avatar asked Oct 15 '25 21:10

Hulk Man


1 Answers

In my case the problem was caused by the Npcap driver, which I use for Wireshark. Disabling Npcap Loopback Adapter in Windows Control Panel\Network and Internet\Network Connections fixed the 9 seconds delay that I had.

The delay itself happens in the Inet6AddressImpl.getHostByAddr(byte[] addr) method (called by InetAddress.getCanonicalHostName()), which is native, so it's hard to say what's going on other than it's DNS related.

like image 55
John29 Avatar answered Oct 17 '25 12:10

John29



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!