You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Adrian Sutton <ad...@intencha.com> on 2003/04/10 00:47:29 UTC

MultiThreadedHttpConnectionManager Questions

It seems the MultiThreadedHttpConnectionManager has become popular of 
late. :)  A couple of questions came through the commons-user list 
today that I thought I'd point out over here.

Firstly, the method:
public HttpConnection getConnection(HostConfiguration hostConfiguration)

has a while (true) loop that catches and logs all HttpExceptions.  The 
method doesn't claim to thrown IOExceptions so it looks like if 
something goes wrong it will loop forever.  I can't believe noone's run 
into this problem yet (though it may be contributing to some of the 
threads going awol in bug 18596 that Mike has been working on).  I have 
asked the user to file a bug report on this to be sure the concern 
isn't lost anyway.

Secondly, an enquiry came through regarding how to determine the number 
of "connections available" (where "connections available" means free 
connections + connections that can be created before reaching 
maxConnections).  I suggested:

manager.getMaxConnectionsPerHost() - 
manager.getConnectionsInUse(hostConfiguration);

However the proposed patch for bug 18596 makes this more complex.  So 
could there be a request for a method that determines how many 
connections can be made gets added?

The support desk seems to be having trouble keeping up with the 
developers lately. :)

Adrian Sutton.


Re: MultiThreadedHttpConnectionManager Questions

Posted by Adrian Sutton <ad...@intencha.com>.
Hi Mike,

> This method looks a little suspicious at first I agree.  Though, as it 
> turns out the HttpException is only thrown when a connection wait 
> timeout occurs.  In the case of  getConnection(HostConfiguration) this 
> will  never occur since we are waiting indefinitely.  The 
> try/catch/loop is just there to make the compiler happy, and the LOG 
> statement was added for completeness.  I have added a comment 
> detailing this to my latest patch for bug 18596.

Thanks Mike, I figured it had to be something like that but just 
couldn't verify it completely.

>> Secondly, an enquiry came through regarding how to determine the 
>> number of "connections available" (where "connections available" 
>> means free connections + connections that can be created before 
>> reaching maxConnections).  I suggested:
>>
>> manager.getMaxConnectionsPerHost() - 
>> manager.getConnectionsInUse(hostConfiguration);
>>
>> However the proposed patch for bug 18596 makes this more complex.  So 
>> could there be a request for a method that determines how many 
>> connections can be made gets added?
>
> The patch for 18596 has methods for getting the max number of 
> connections and the total number in use.  Are you also wondering how 
> many idle connections there are?

No, the question seems to be: how many more methods can I execute 
without having to wait for another connection to become available?  We 
the current code in CVS the answer is simply total allowed connections 
for the hose - the connections in use for the host.  With the new code 
you also have to take into consideration the total number of 
connections for any host.  So it becomes Math.min(maxTotal - 
inUseTotal, maxHost - inUseHost); which could be implemented outside of 
the connection manager but it may be worth adding a convenience method. 
  I'm not at all concerned whether or not it goes in, rather just 
passing on a user request.

> Mike

Thanks for the info,

Adrian.


Re: MultiThreadedHttpConnectionManager Questions

Posted by Michael Becke <be...@u.washington.edu>.
Hi Adrian,

> Firstly, the method:
> public HttpConnection getConnection(HostConfiguration 
> hostConfiguration)
>
> has a while (true) loop that catches and logs all HttpExceptions.  The 
> method doesn't claim to thrown IOExceptions so it looks like if 
> something goes wrong it will loop forever.  I can't believe noone's 
> run into this problem yet (though it may be contributing to some of 
> the threads going awol in bug 18596 that Mike has been working on).  I 
> have asked the user to file a bug report on this to be sure the 
> concern isn't lost anyway.

This method looks a little suspicious at first I agree.  Though, as it 
turns out the HttpException is only thrown when a connection wait 
timeout occurs.  In the case of  getConnection(HostConfiguration) this 
will  never occur since we are waiting indefinitely.  The 
try/catch/loop is just there to make the compiler happy, and the LOG 
statement was added for completeness.  I have added a comment detailing 
this to my latest patch for bug 18596.

> Secondly, an enquiry came through regarding how to determine the 
> number of "connections available" (where "connections available" means 
> free connections + connections that can be created before reaching 
> maxConnections).  I suggested:
>
> manager.getMaxConnectionsPerHost() - 
> manager.getConnectionsInUse(hostConfiguration);
>
> However the proposed patch for bug 18596 makes this more complex.  So 
> could there be a request for a method that determines how many 
> connections can be made gets added?

The patch for 18596 has methods for getting the max number of 
connections and the total number in use.  Are you also wondering how 
many idle connections there are?

Mike