Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 365828

Summary: Use IP address instead of DNS name for client address
Product: [RT] Jetty Reporter: Jan Bartel <janb>
Component: clientAssignee: Project Inbox <jetty-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: gregw, jetty-inbox, tigergui1990
Version: 7.6.0.RC0   
Target Milestone: 7.6.x   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Jan Bartel CLA 2011-12-07 01:53:54 EST
I found a issue about HttpClient, as we know, before each HttpExchange
be sent, it will associate with an idle HttpConnection first, this
associate function is simple like this:

void associate(AbstractHttpConnection connection)
   {
       if (connection.getEndPoint().getLocalHost()!= null)
           _localAddress = new
Address(connection.getEndPoint().getLocalHost(),connection.getEndPoint().getLocalPort());
       _connection = connection;
       if (getStatus() == STATUS_CANCELLING)
           abort();
   }

But in one of my online service, one day, i found that It cost me
about 50 ~ 200 ms to connect to other http service if i use Jetty
HttpClient, it is unnormal, usually, it cost only 1 - 2 ms. So,
problem comes, at last, i found this associate function make this
happen.

"connection.getEndPoint().getLocalHost()" cost usually 50 ~ 200 ms, it
use function getCanonicalHostName() of Java InetAddress class. In some
cases, this function will go through DNS server to get the host name,
so its time taken is very long.

As this associate function was invoked before each http package sent
(In Jetty 7.4, this function was invoked twice one we sent a http
package), it is very important and we should keep its time taken is
short. So, why don't we  change

connection.getEndPoint().getLocalHost()

to

connection.getEndPoint().getLocalAddr()

It will works well, and will prevent this kind of problems. I do not
know whether it is a bug, but i hope you guys can fix it, thank you.
Comment 1 Greg Wilkins CLA 2012-01-30 22:49:30 EST
fixed