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 Stefan Sobernig <ss...@thinkersfoot.net.INVALID> on 2017/09/25 15:38:52 UTC

Introspection (time probes): AsyncHttpClient

Hi everybody,

I want to collect (execution) timing probes from various processing
stages of a request/response inside an AsyncHttpClient (running HC 5
alpha 2 & friends).

So far, I rougly implemented sth. sketched out my Oleg in this posting I
found when crawling the archive:

> In this case you should have a pool of HttpClient instances each
> configured to use a small pool of connections (2 to 5). This setup will
> be more representative of thousands of concurrent browser connections.
> With one large pool of connections you basically have 1000 thousand of
> threads constantly contending for one global pool lock. 

http://httpcomponents.10934.n7.nabble.com/Scalable-Http-Client-td20712.html

I have some follow-up questions:

1) How to best emit timing probes (start, end time) for a
request/response pair: Setup a pair of correlated request/response
interceptors? Instrument the FutureCallback callback methods? Right now,
I collect at every of those, but the start times (FutureCallback
construction, request interceptor) do not match my intention, as they
are processed before the request is eventually executed. There is
clearly sth. more appropriate that I am missing ...

2) How can I best collect timing probes from establishing the underlying
connections? (connection established times).

3) "a small pool of connections (2 to 5)" Am I reading this correctly,
that each AsyncHttpClient instance should be equipped with its own
connection manager (setConnectionManager), with setMaxConnTotal(5) and
setMaxConnPerRoute(5), assuming that each pool has a min of 2? Can I
influence the minimum number of connections?

4) If I want to force my AsyncHttpClients/async HttpRequests setup into
a blocking, sequential variant (as implemented using a loop over a
BasicHttpClient), can I use a semaphore as hinted at here:

> final Semaphore semaphore = new Semaphore(1);

https://stackoverflow.com/questions/30101865/how-to-configure-the-number-of-allowed-pending-requests-in-apache-async-client

Any hints would be greatly appreciated!

Thx,
Stefan

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


Re: Introspection (time probes): AsyncHttpClient

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2017-09-26 at 12:18 +0200, Stefan Sobernig wrote:
> > > > >  with setMaxConnTotal(5) and
> > > > > setMaxConnPerRoute(5), assuming that each pool has a min of
> > > > > 2?
> > > > > Can I
> > > > > influence the minimum number of connections?
> > > > > 
> > > > 
> > > > I am not sure I understand.
> > > 
> > > How can I configure a pool for a given AsyncHttpClient for a size
> > > 2-5
> > > (or 3-10 etc.)?
> > 
> > Please use PoolingAsyncClientConnectionManagerBuilder to build an
> > instance of PoolingAsyncClientConnectionManager with the desired
> > settings or change the settings of an existing
> > PoolingAsyncClientConnectionManager through ConnPoolControl
> > interface.
> 
> Ok, will try that. On first sight, however, I do not see how to set
> the
> lower pool size bound (2, 3)?
> 

There is no such control settings. All persistent are kept alive as
long as they are deemed valid. There is no way to keep a connection
alive if it is considered non-usable.


> https://github.com/apache/httpcomponents-
> client/blob/d2b3385ba2b655d9942263964aad78bcca391bda/httpclient5/src/
> main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConne
> ctionManagerBuilder.java
> 
> Another question: I would like to test (enforce) HTTP/1.0 *no*
> keep-alive mode in my setup. My plan is to set:
> 
> 1. myRequest.setProtocolVersion(HttpVersion.HTTP_1_0)
> 2. drop any Keep-Alive header from the actual responses (using a
> response interceptor?)
> 

Both approaches should work (the latter being slightly more
preferable).


> Or is it more straightforward to define my own
> ConnectionKeepAliveStrategy?
> 

The ConnectionReuseStrategy can make the ultimate decision whether or
not the connection can be kept alive but at that point it is already
too late to inform the opposite endpoint of the intent. It is perfectly
legal to drop the connection without sending 'Connection: close'
message header but not very nice.

Hope this helps

Oleg  


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


Re: Introspection (time probes): AsyncHttpClient

Posted by Stefan Sobernig <ss...@thinkersfoot.net.INVALID>.
>>>>  with setMaxConnTotal(5) and
>>>> setMaxConnPerRoute(5), assuming that each pool has a min of 2?
>>>> Can I
>>>> influence the minimum number of connections?
>>>>
>>> I am not sure I understand.
>> How can I configure a pool for a given AsyncHttpClient for a size 2-5
>> (or 3-10 etc.)?
>
> Please use PoolingAsyncClientConnectionManagerBuilder to build an
> instance of PoolingAsyncClientConnectionManager with the desired
> settings or change the settings of an existing
> PoolingAsyncClientConnectionManager through ConnPoolControl interface.

Ok, will try that. On first sight, however, I do not see how to set the
lower pool size bound (2, 3)?

https://github.com/apache/httpcomponents-client/blob/d2b3385ba2b655d9942263964aad78bcca391bda/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java

Another question: I would like to test (enforce) HTTP/1.0 *no*
keep-alive mode in my setup. My plan is to set:

1. myRequest.setProtocolVersion(HttpVersion.HTTP_1_0)
2. drop any Keep-Alive header from the actual responses (using a
response interceptor?)

Or is it more straightforward to define my own ConnectionKeepAliveStrategy?

Many thanks,
Stefan

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


Re: Introspection (time probes): AsyncHttpClient

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2017-09-26 at 11:51 +0200, Stefan Sobernig wrote:
> Hi Oleg!
> 
> Thx for the swift reply, turned out very helpful :)
> 

...


> > >  with setMaxConnTotal(5) and
> > > setMaxConnPerRoute(5), assuming that each pool has a min of 2?
> > > Can I
> > > influence the minimum number of connections?
> > > 
> > 
> > I am not sure I understand.
> 
> How can I configure a pool for a given AsyncHttpClient for a size 2-5
> (or 3-10 etc.)?


Please use PoolingAsyncClientConnectionManagerBuilder to build an
instance of PoolingAsyncClientConnectionManager with the desired
settings or change the settings of an existing
PoolingAsyncClientConnectionManager through ConnPoolControl interface.

Hope this helps

Oleg

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


Re: Introspection (time probes): AsyncHttpClient

Posted by Stefan Sobernig <ss...@thinkersfoot.net.INVALID>.
Hi Oleg!

Thx for the swift reply, turned out very helpful :)

>> Hi everybody,
>>
>> I want to collect (execution) timing probes from various processing
>> stages of a request/response inside an AsyncHttpClient (running HC 5
>> alpha 2 & friends).
>>
>> So far, I rougly implemented sth. sketched out my Oleg in this
>> posting I
>> found when crawling the archive:
>>
>>> In this case you should have a pool of HttpClient instances each
>>> configured to use a small pool of connections (2 to 5). This setup
>>> will
>>> be more representative of thousands of concurrent browser
>>> connections.
>>> With one large pool of connections you basically have 1000 thousand
>>> of
>>> threads constantly contending for one global pool lock. 
>> http://httpcomponents.10934.n7.nabble.com/Scalable-Http-Client-td2071
>> 2.html
>>
> As of 5.0-alpha3 HttpClient also supports so called lax (or concurrent)
> connection pooling which does not involve a global lock. 

Ok, I will check that later.
>
>
>> I have some follow-up questions:
>>
>> 1) How to best emit timing probes (start, end time) for a
>> request/response pair: Setup a pair of correlated request/response
>> interceptors? 
> By using an execution interceptor:
>
> https://github.com/apache/httpcomponents-client/blob/master/httpclient5
> /src/main/java/org/apache/hc/client5/http/async/AsyncExecChainHandler.j
> ava
>
> See these examples
>
> https://github.com/apache/httpcomponents-client/blob/master/httpclient5
> /src/examples/org/apache/hc/client5/http/examples/ClientInterceptors.ja
> va
>
> https://github.com/apache/httpcomponents-client/blob/master/httpclient5
> /src/examples/org/apache/hc/client5/http/examples/AsyncClientMessageTra
> ilers.java
Ok, done.
>> 2) How can I best collect timing probes from establishing the
>> underlying
>> connections? (connection established times).
>>
> By using a custom AsyncClientConnectionOperator, I think
>
> https://github.com/apache/httpcomponents-client/blob/master/httpclient5
> /src/main/java/org/apache/hc/client5/http/nio/AsyncClientConnectionOper
> ator.java

Ok, I will have to take a closer look on how to implant my custom
operator then. But I got the idea.
>
>
>> 3) "a small pool of connections (2 to 5)" Am I reading this
>> correctly,
>> that each AsyncHttpClient instance should be equipped with its own
>> connection manager (setConnectionManager),
> Yes.
>
>
>>  with setMaxConnTotal(5) and
>> setMaxConnPerRoute(5), assuming that each pool has a min of 2? Can I
>> influence the minimum number of connections?
>>
> I am not sure I understand.
How can I configure a pool for a given AsyncHttpClient for a size 2-5
(or 3-10 etc.)?
>> 4) If I want to force my AsyncHttpClients/async HttpRequests setup
>> into
>> a blocking, sequential variant (as implemented using a loop over a
>> BasicHttpClient), can I use a semaphore as hinted at here:
> A Semaphore can help limit the total number of concurrent connections.
> If you want to sequentially execute requests you just need to wait on
> the response future before proceeding to the next request.
I see, too obvious for me, heh :)

Stefan


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


Re: Introspection (time probes): AsyncHttpClient

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, 2017-09-25 at 17:38 +0200, Stefan Sobernig wrote:
> Hi everybody,
> 
> I want to collect (execution) timing probes from various processing
> stages of a request/response inside an AsyncHttpClient (running HC 5
> alpha 2 & friends).
> 
> So far, I rougly implemented sth. sketched out my Oleg in this
> posting I
> found when crawling the archive:
> 
> > In this case you should have a pool of HttpClient instances each
> > configured to use a small pool of connections (2 to 5). This setup
> > will
> > be more representative of thousands of concurrent browser
> > connections.
> > With one large pool of connections you basically have 1000 thousand
> > of
> > threads constantly contending for one global pool lock. 
> 
> http://httpcomponents.10934.n7.nabble.com/Scalable-Http-Client-td2071
> 2.html
> 

As of 5.0-alpha3 HttpClient also supports so called lax (or concurrent)
connection pooling which does not involve a global lock. 


> I have some follow-up questions:
> 
> 1) How to best emit timing probes (start, end time) for a
> request/response pair: Setup a pair of correlated request/response
> interceptors? 

By using an execution interceptor:

https://github.com/apache/httpcomponents-client/blob/master/httpclient5
/src/main/java/org/apache/hc/client5/http/async/AsyncExecChainHandler.j
ava

See these examples

https://github.com/apache/httpcomponents-client/blob/master/httpclient5
/src/examples/org/apache/hc/client5/http/examples/ClientInterceptors.ja
va

https://github.com/apache/httpcomponents-client/blob/master/httpclient5
/src/examples/org/apache/hc/client5/http/examples/AsyncClientMessageTra
ilers.java

> Instrument the FutureCallback callback methods? Right now,
> I collect at every of those, but the start times (FutureCallback
> construction, request interceptor) do not match my intention, as they
> are processed before the request is eventually executed. There is
> clearly sth. more appropriate that I am missing ...
> 
> 2) How can I best collect timing probes from establishing the
> underlying
> connections? (connection established times).
> 

By using a custom AsyncClientConnectionOperator, I think

https://github.com/apache/httpcomponents-client/blob/master/httpclient5
/src/main/java/org/apache/hc/client5/http/nio/AsyncClientConnectionOper
ator.java


> 3) "a small pool of connections (2 to 5)" Am I reading this
> correctly,
> that each AsyncHttpClient instance should be equipped with its own
> connection manager (setConnectionManager),

Yes.


>  with setMaxConnTotal(5) and
> setMaxConnPerRoute(5), assuming that each pool has a min of 2? Can I
> influence the minimum number of connections?
> 

I am not sure I understand.


> 4) If I want to force my AsyncHttpClients/async HttpRequests setup
> into
> a blocking, sequential variant (as implemented using a loop over a
> BasicHttpClient), can I use a semaphore as hinted at here:
> 

A Semaphore can help limit the total number of concurrent connections.
If you want to sequentially execute requests you just need to wait on
the response future before proceeding to the next request.

Hope this helps

Oleg  

> > final Semaphore semaphore = new Semaphore(1);
> 
> https://stackoverflow.com/questions/30101865/how-to-configure-the-num
> ber-of-allowed-pending-requests-in-apache-async-client
> 
> Any hints would be greatly appreciated!
> 
> Thx,
> Stefan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 

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