Discussion:
Introspection (time probes): AsyncHttpClient
Stefan Sobernig
2017-09-25 15:38:52 UTC
Permalink
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
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
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-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Oleg Kalnichevski
2017-09-25 19:25:44 UTC
Permalink
Post by Stefan Sobernig
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
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.
Post by Stefan Sobernig
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
Post by Stefan Sobernig
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
Post by Stefan Sobernig
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.
Post by Stefan Sobernig
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.
Post by Stefan Sobernig
4) If I want to force my AsyncHttpClients/async HttpRequests setup into
a blocking, sequential variant (as implemented using a loop over a
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
Post by Stefan Sobernig
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-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Stefan Sobernig
2017-09-26 09:51:28 UTC
Permalink
Hi Oleg!

Thx for the swift reply, turned out very helpful :)
Post by Oleg Kalnichevski
Post by Stefan Sobernig
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
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.
Post by Oleg Kalnichevski
Post by Stefan Sobernig
1) How to best emit timing probes (start, end time) for a
request/response pair: Setup a pair of correlated request/response
interceptors?
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.
Post by Oleg Kalnichevski
Post by Stefan Sobernig
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.
Post by Oleg Kalnichevski
Post by Stefan Sobernig
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.
Post by Stefan Sobernig
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.)?
Post by Oleg Kalnichevski
Post by Stefan Sobernig
4) If I want to force my AsyncHttpClients/async HttpRequests setup into
a blocking, sequential variant (as implemented using a loop over a
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-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Oleg Kalnichevski
2017-09-26 09:58:57 UTC
Permalink
Post by Stefan Sobernig
Hi Oleg!
Thx for the swift reply, turned out very helpful :)
...
Post by Stefan Sobernig
Post by Oleg Kalnichevski
 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-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Stefan Sobernig
2017-09-26 10:18:39 UTC
Permalink
Post by Oleg Kalnichevski
Post by Stefan Sobernig
Post by Oleg Kalnichevski
 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-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Oleg Kalnichevski
2017-09-26 13:29:07 UTC
Permalink
Post by Stefan Sobernig
Post by Oleg Kalnichevski
Post by Stefan Sobernig
Post by Oleg Kalnichevski
 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.
Post by Stefan Sobernig
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*
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).
Post by Stefan Sobernig
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-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Loading...