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 TomStrummer <to...@gmail.com> on 2008/12/18 20:33:47 UTC

ThreadSafeClientConnManager and pool size

Hi, 

I'm working on a project that creates a simple HTTP client "builder DSL" for
the Groovy programming language
(http://groovy.codehaus.org/modules/http-builder/).  Built on HttpClient 4.

One feature I'm trying to add is a builder that automatically executes
requests asynchronously.  This is easy to do (from a user standpoint)
because their response handling code is already packaged in a closure which
is easy to execute asynchronously. (think Prototype.js' Ajax.Request).

So I have three questions:

I'm looking at ThreadSafeClientConnManager and I'm wondering why it doesn't
use a java.util.concurrent ThreadPoolExecutor to allow for a dynamic pool
size?  It looks like there are a number of classes in that package to handle
general concurrency and I'm wondering why the concurrent* library wasn't
used.  

Is it true that HttpClient 4 already requires Java 1.5?

I'd also consider using NIO but from what I read in another thread, it's
inefficient unless you're talking thousands of simultaneous requests,
correct?  I'm not expecting my code to be used for anything like that :) 
But I thought a flexible pool size would be a nice feature :)

Thanks for the input. 

-Tom


-- 
View this message in context: http://www.nabble.com/ThreadSafeClientConnManager-and-pool-size-tp21079444p21079444.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


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


Re: ThreadSafeClientConnManager and pool size

Posted by TomStrummer <to...@gmail.com>.

olegk wrote:
> 
> TSCM is perfectly capable of reducing the size of its pool after a spike
> of activity. It will be gradually removing connections from the pool as
> they become expired. One can have a better control of this process by
> running a helper thread and calling #closeExpiredConnections() or
> #closeIdleConnections() every once in a while.
> 
> That's why I personally see no harm in keeping the maximum number of
> connections per host set to a fairly high value, as long as you do not
> mind having lots and lots of connections as a result of a sudden burst
> of requests.
> 

Oh cool I didn't realize TSCCM did that.  Thanks.
-- 
View this message in context: http://www.nabble.com/ThreadSafeClientConnManager-and-pool-size-tp21079444p21146125.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


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


Re: ThreadSafeClientConnManager and pool size

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, 2008-12-22 at 06:41 -0800, TomStrummer wrote:
> 
> olegk wrote:
> > 
> > I think so, but I just do not see a point. Why not just setting a higher 
> > connections per host number? TSCM does not pre-allocate connections, so 
> > the pool will never grow, unless really needed.
> > 
> 
> I guess the difference is ThreadPoolExecutor sets a TTL on Thread instances
> so in addition to being able to scale up, it can scale back down.  If, for
> instance, there is a burst in requests then a drop, a large number of
> objects are not left in the pool.  I guess this question is mostly academic
> since I don't really have much of a use case behind what I'm asking for.  I
> originally would have had the "max concurrent request count" be a mutable
> property on my AsyncHTTPBuilder class rather than a final value set in a
> constructor.  But since TSCCM's pool size is not dynamic, it means mine
> can't be either unless I create a new one each time the value is changed --
> which I don't want to do.  But anyway, it is not really a problem.
> 
> 

TSCM is perfectly capable of reducing the size of its pool after a spike
of activity. It will be gradually removing connections from the pool as
they become expired. One can have a better control of this process by
running a helper thread and calling #closeExpiredConnections() or
#closeIdleConnections() every once in a while.

That's why I personally see no harm in keeping the maximum number of
connections per host set to a fairly high value, as long as you do not
mind having lots and lots of connections as a result of a sudden burst
of requests.

Hope this helps

Oleg  

> 
> olegk wrote:
> > 
> > I have not used retrotranslator myself so I cannot really tell.
> > 
> > We held a poll on the minimal JRE level for HttpClient 4.0 about a year 
> > ago, and if my memory does not fail me, not a single person voted in 
> > favor of 1.4 compatibility:
> > 
> 
> If HC 4 is built with maven, it's easy to add in Retrotranslator via the
> plugin:
> http://mojo.codehaus.org/retrotranslator-maven-plugin/examples/project-translation.html
> 
> But i suppose I don't have a real requirement for that either, I would have
> done it "just because" :)


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


Re: ThreadSafeClientConnManager and pool size

Posted by TomStrummer <to...@gmail.com>.

olegk wrote:
> 
> I think so, but I just do not see a point. Why not just setting a higher 
> connections per host number? TSCM does not pre-allocate connections, so 
> the pool will never grow, unless really needed.
> 

I guess the difference is ThreadPoolExecutor sets a TTL on Thread instances
so in addition to being able to scale up, it can scale back down.  If, for
instance, there is a burst in requests then a drop, a large number of
objects are not left in the pool.  I guess this question is mostly academic
since I don't really have much of a use case behind what I'm asking for.  I
originally would have had the "max concurrent request count" be a mutable
property on my AsyncHTTPBuilder class rather than a final value set in a
constructor.  But since TSCCM's pool size is not dynamic, it means mine
can't be either unless I create a new one each time the value is changed --
which I don't want to do.  But anyway, it is not really a problem.



olegk wrote:
> 
> I have not used retrotranslator myself so I cannot really tell.
> 
> We held a poll on the minimal JRE level for HttpClient 4.0 about a year 
> ago, and if my memory does not fail me, not a single person voted in 
> favor of 1.4 compatibility:
> 

If HC 4 is built with maven, it's easy to add in Retrotranslator via the
plugin:
http://mojo.codehaus.org/retrotranslator-maven-plugin/examples/project-translation.html

But i suppose I don't have a real requirement for that either, I would have
done it "just because" :)
-- 
View this message in context: http://www.nabble.com/ThreadSafeClientConnManager-and-pool-size-tp21079444p21128914.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


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


Re: ThreadSafeClientConnManager and pool size

Posted by Oleg Kalnichevski <ol...@apache.org>.
TomStrummer wrote:
> 
> 
> olegk wrote:
>> ThreadSafeClientConnManager and ThreadPoolExecutor serve completely
>> different purposes and are complimentary in their functions. The former
>> manages a pool of objects, whereas the latter manages threads of
>> execution. One can use ThreadPoolExecutor to execute multiple requests
>> that obtain connections from a connection pool managed by
>> ThreadSafeClientConnManager.
>>
> 
> Ah, I see.  Then I'll ask the more direct question -- would it be possible/
> reasonable to make the max pool size adjustable, similar to how
> ThreadPoolExecutor manages its thread pool size?  
> 
> 

I think so, but I just do not see a point. Why not just setting a higher 
connections per host number? TSCM does not pre-allocate connections, so 
the pool will never grow, unless really needed.

> olegk wrote:
>>> Is it true that HttpClient 4 already requires Java 1.5?
>>>
>> Yes, it is.
>>
> 
> Ok.  I'm guessing it's not something that could be handled by
> retrotranslator to get a 1.4 compatible binary?
> 

I have not used retrotranslator myself so I cannot really tell.

We held a poll on the minimal JRE level for HttpClient 4.0 about a year 
ago, and if my memory does not fail me, not a single person voted in 
favor of 1.4 compatibility:

http://www.nabble.com/-POLL--Minimal-JRE-for-HttpClient-4.0-to13874820.html#a13874820

If upgrading to Java 1.5 is not an option for you, consider using 
HttpClient 3.1 or building a custom HTTP client based on HttpCore 4.0, 
which is still Java 1.3 compatible.

> 
> Thanks Oleg for taking your time to respond to my questions.  I appreciate
> it.
>

You are welcome.

Cheers

Oleg


> -Tom


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


Re: ThreadSafeClientConnManager and pool size

Posted by TomStrummer <to...@gmail.com>.


olegk wrote:
> 
> ThreadSafeClientConnManager and ThreadPoolExecutor serve completely
> different purposes and are complimentary in their functions. The former
> manages a pool of objects, whereas the latter manages threads of
> execution. One can use ThreadPoolExecutor to execute multiple requests
> that obtain connections from a connection pool managed by
> ThreadSafeClientConnManager.
> 

Ah, I see.  Then I'll ask the more direct question -- would it be possible/
reasonable to make the max pool size adjustable, similar to how
ThreadPoolExecutor manages its thread pool size?  



olegk wrote:
> 
>>  It looks like there are a number of classes in that package to handle
>> general concurrency and I'm wondering why the concurrent* library wasn't
>> used.  
>> 
> 
> There is a plenty of references to standard java.util.concurrent
> primitives in the TSCM classes, as far as I can tell.
> 

Ok thanks for the clarification.  To be honest I did not look that far into
the source code.



olegk wrote:
> 
>> Is it true that HttpClient 4 already requires Java 1.5?
>> 
> 
> Yes, it is.
> 

Ok.  I'm guessing it's not something that could be handled by
retrotranslator to get a 1.4 compatible binary?


Thanks Oleg for taking your time to respond to my questions.  I appreciate
it.

-Tom
-- 
View this message in context: http://www.nabble.com/ThreadSafeClientConnManager-and-pool-size-tp21079444p21096080.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


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


Re: ThreadSafeClientConnManager and pool size

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2008-12-18 at 11:33 -0800, TomStrummer wrote:
> Hi, 
> 
> I'm working on a project that creates a simple HTTP client "builder DSL" for
> the Groovy programming language
> (http://groovy.codehaus.org/modules/http-builder/).  Built on HttpClient 4.
> 
> One feature I'm trying to add is a builder that automatically executes
> requests asynchronously.  This is easy to do (from a user standpoint)
> because their response handling code is already packaged in a closure which
> is easy to execute asynchronously. (think Prototype.js' Ajax.Request).
> 
> So I have three questions:
> 
> I'm looking at ThreadSafeClientConnManager and I'm wondering why it doesn't
> use a java.util.concurrent ThreadPoolExecutor to allow for a dynamic pool
> size? 

ThreadSafeClientConnManager and ThreadPoolExecutor serve completely
different purposes and are complimentary in their functions. The former
manages a pool of objects, whereas the latter manages threads of
execution. One can use ThreadPoolExecutor to execute multiple requests
that obtain connections from a connection pool managed by
ThreadSafeClientConnManager.

>  It looks like there are a number of classes in that package to handle
> general concurrency and I'm wondering why the concurrent* library wasn't
> used.  
> 

There is a plenty of references to standard java.util.concurrent
primitives in the TSCM classes, as far as I can tell.

> Is it true that HttpClient 4 already requires Java 1.5?
> 

Yes, it is.

> I'd also consider using NIO but from what I read in another thread, it's
> inefficient unless you're talking thousands of simultaneous requests,
> correct? 

The NIO model and the classic IO model have both advantages and
disadvantages. The blocking I/O significantly outperforms NIO in terms
of raw throughput on mainstream JVMs. However, in systems with high
latency connections, worker threads can stay blocked in an input
operation for many seconds or even minutes, which significantly degrades
the system's ability to scale. With a great number of simultaneous
connections the system can end up spending most of its processing time
switching contexts of idle threads. So, one should use NIO where
appropriate.

HttpCore, the set of low level HTTP transport components HttpClient is
based on, provides support for both blocking and non-blocking I/O
models. 

Hope this helps

Oleg


>  I'm not expecting my code to be used for anything like that :) 
> But I thought a flexible pool size would be a nice feature :)
> 
> Thanks for the input. 
> 
> -Tom
> 
> 


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