You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Oleg Kalnichevski <ol...@apache.org> on 2012/08/01 17:58:23 UTC
Re: Async http client experiments....
On Mon, 2012-07-30 at 19:47 -0400, Daniel Kulp wrote:
> On Monday, July 30, 2012 11:41:55 PM Oleg Kalnichevski wrote:
> > On Mon, 2012-07-30 at 17:06 -0400, Daniel Kulp wrote:
> > > BTW: I think the NHttpClient.java referenced from:
> > > http://hc.apache.org/httpcomponents-core-ga/examples.html
> > > needs work as well. I don't think most of the parameters set in the
> > > HttpParams actually will actually go into effect. That was part of my
> > > original issue as the TCP_NODELAY setting didn't take effect until I set
> > > that on the ConnectingIOReactor instead of in the params. Not sure if
> > > it's a bug in the BasicNIOConnPool that was ignoring the params or a bug
> > > in the example. Looking at the code in BasicNIOConnPool, I think the
> > > connection timeout is the only setting that would work from the params.
> >
> > Higher level components such as HttpAsyncClient usually take care of
> > creating and initializing the I/O reactor based on the HTTP level
> > parameters. When using core components directly more work may be needed.
> > I/O reactor config in NHttpClient is obviously wrong. TCP_NODELAY should
> > actually be set to true per default, which is something I clearly
> > overlooked.
>
> I was JUST about to ask about that. :-) false is OK for GET requests,
> but for PUT/POST, it completely kills performance as it adds up to a 200ms
> delay between sending the headers and the body as it waits for the ack of
> the headers. Would you like me to log some issues in JIRA for these so
> they get tracked?
>
Hi Daniel
I believe I have fixed the thread synchronization issue. All tests
repeatedly passed for me. Could you please have a look at my changes and
confirm that everything is more or less sane and HTTP transport still
performs at an acceptable level?
As the next I could optimize the code and hopefully bring its
performance closer to that of the default blocking transport.
I also noticed that for some reason additional connections get open and
closed without transmitting any data, which obviously should not be
happening. I'll investigate the problem if you confirm that you want me
to proceed.
Cheers
Oleg
Re: Async http client experiments....
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2012-09-06 at 10:14 -0400, Daniel Kulp wrote:
> On Sep 6, 2012, at 9:42 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
>
> > On Wed, 2012-09-05 at 15:30 -0400, Daniel Kulp wrote:
> >> On Sep 5, 2012, at 10:49 AM, Daniel Kulp <dk...@apache.org> wrote:
> >>
> >> OK. Went ahead and ripped out the HttpHost related stuff and replaced with a CXFHttpHost which is basically a copy of the HttpHost with extra params for the TLS and Proxy stuff (Proxy stuff unused right now). With that, we're back to a single connection for all the TLS requests (providing they CAN). So that looks good now. That pretty much just leaves the Proxy stuff as the major missing piece.
> >>
> >
> > Would not aggregation be more appropriate here?
> >
> > class CXFRoute {
> >
> > HttpHost host;
> > HttpHost proxy;
> > SSLStuff sstuff;
> >
> > }
>
> Possibly, but if HttpHost is eventually made non-final, with the current setup it would be very trivial to rip out large chunks of code. :-)
>
>
No problem at all. Besides, if this experimental code eventually lends
in the main code line I'll make sure generic bits get migrated back to
the framework. This should help reduce the footprint of custom code you
need to maintain internally. I have already made necessary changes to
the shared content i/o classes in the 4.3 branch of HttpCore so that
they could be used instead of the custom classes currently in the
sandbox.
Oleg
Re: Async http client experiments....
Posted by Daniel Kulp <dk...@apache.org>.
On Sep 6, 2012, at 9:42 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Wed, 2012-09-05 at 15:30 -0400, Daniel Kulp wrote:
>> On Sep 5, 2012, at 10:49 AM, Daniel Kulp <dk...@apache.org> wrote:
>>
>> OK. Went ahead and ripped out the HttpHost related stuff and replaced with a CXFHttpHost which is basically a copy of the HttpHost with extra params for the TLS and Proxy stuff (Proxy stuff unused right now). With that, we're back to a single connection for all the TLS requests (providing they CAN). So that looks good now. That pretty much just leaves the Proxy stuff as the major missing piece.
>>
>
> Would not aggregation be more appropriate here?
>
> class CXFRoute {
>
> HttpHost host;
> HttpHost proxy;
> SSLStuff sstuff;
>
> }
Possibly, but if HttpHost is eventually made non-final, with the current setup it would be very trivial to rip out large chunks of code. :-)
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com
Re: Async http client experiments....
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2012-09-05 at 15:30 -0400, Daniel Kulp wrote:
> On Sep 5, 2012, at 10:49 AM, Daniel Kulp <dk...@apache.org> wrote:
>
> >
> > On Sep 5, 2012, at 9:26 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> >>
> >> Just ditch HttpHost. You obviously need a richer class to represent
> >> connection routes. HttpClient has HttpRoute class for that matter. You
> >> probably should be using a custom class that also includes HTTP proxy
> >> and SSL context bits specific to CXF.
> >>
> >> Does this help you in any way?
> >
> > Yep. Just feels like I have to subclass/override a lot of behavior from HC instead of "using" it. If HttpHost wasn't final, it would be so much more useful. Is there a particular reason why it has to be final?
> >
> > Still not sure about the Proxy stuff at all, but that's likely because I don't know much about Proxies at all. I'll likely need to look more into what proxy stuff does on the wire.
>
> OK. Went ahead and ripped out the HttpHost related stuff and replaced with a CXFHttpHost which is basically a copy of the HttpHost with extra params for the TLS and Proxy stuff (Proxy stuff unused right now). With that, we're back to a single connection for all the TLS requests (providing they CAN). So that looks good now. That pretty much just leaves the Proxy stuff as the major missing piece.
>
Would not aggregation be more appropriate here?
class CXFRoute {
HttpHost host;
HttpHost proxy;
SSLStuff sstuff;
}
Oleg
Re: Async http client experiments....
Posted by Daniel Kulp <dk...@apache.org>.
On Sep 5, 2012, at 10:49 AM, Daniel Kulp <dk...@apache.org> wrote:
>
> On Sep 5, 2012, at 9:26 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
>>
>> Just ditch HttpHost. You obviously need a richer class to represent
>> connection routes. HttpClient has HttpRoute class for that matter. You
>> probably should be using a custom class that also includes HTTP proxy
>> and SSL context bits specific to CXF.
>>
>> Does this help you in any way?
>
> Yep. Just feels like I have to subclass/override a lot of behavior from HC instead of "using" it. If HttpHost wasn't final, it would be so much more useful. Is there a particular reason why it has to be final?
>
> Still not sure about the Proxy stuff at all, but that's likely because I don't know much about Proxies at all. I'll likely need to look more into what proxy stuff does on the wire.
OK. Went ahead and ripped out the HttpHost related stuff and replaced with a CXFHttpHost which is basically a copy of the HttpHost with extra params for the TLS and Proxy stuff (Proxy stuff unused right now). With that, we're back to a single connection for all the TLS requests (providing they CAN). So that looks good now. That pretty much just leaves the Proxy stuff as the major missing piece.
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com
Re: Async http client experiments....
Posted by Daniel Kulp <dk...@apache.org>.
On Sep 11, 2012, at 8:27 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Mon, 2012-09-10 at 17:10 -0400, Daniel Kulp wrote:
>> On Sep 10, 2012, at 6:13 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
>>
>>> I think this problem can be easily fixed. If the expected X500Principal
>>> is known in advance, one can stick it into the local execution context
>>> as ClientContext#USER_TOKEN attribute [1]. This will force the client to
>>> request connections with the given state only.
>>
>> Yep. Worked perfectly.
>>
>> I committed my latest updates to the sandbox. A little more cleanup and I'll likely merge it into the main build.
>>
>> I did do a pretty big update to the SharedOutputBuffer to better handle the case where a large byte[] is passed into the write method. It will now avoid copying blocks out of there into the buffer to then copy into the encoder. Avoids a bunch of copies. Also avoids a bunch of flipping back and forth between threads as the enable/disable output stuff is flipped back and forth.
>>
>>
>
> Great stuff! Actually one probably could apply similar optimization to
> the SharedInputBuffer as well to reduce intermediate buffer copying for
> input operations.
Just did that. That said, it's much less critical there. Woodstox uses an internal 4000 byte buffer for decoding XML. Thus, under "normal" circumstances, we only get 4K byte[]'s in there. That said, I added a little detection in there so if we DO have to wait for data for the 4K buffer, we'll just read directly into that buffer. JAX-RS and maybe MTOM might pass in larger blocks so they may benefit more. Not really sure.
With my simple test case, the updates drop the number of times the main processing thread needed to block for input from about 25% of the time to about 5%. However, this CAN increase the amount of buffer copies. I need to run some tests to see which is worse, they extra byte[] copies that occur on background threads or the waiting by the main thread.
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com
Re: Async http client experiments....
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, 2012-09-10 at 17:10 -0400, Daniel Kulp wrote:
> On Sep 10, 2012, at 6:13 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
>
> > I think this problem can be easily fixed. If the expected X500Principal
> > is known in advance, one can stick it into the local execution context
> > as ClientContext#USER_TOKEN attribute [1]. This will force the client to
> > request connections with the given state only.
>
> Yep. Worked perfectly.
>
> I committed my latest updates to the sandbox. A little more cleanup and I'll likely merge it into the main build.
>
> I did do a pretty big update to the SharedOutputBuffer to better handle the case where a large byte[] is passed into the write method. It will now avoid copying blocks out of there into the buffer to then copy into the encoder. Avoids a bunch of copies. Also avoids a bunch of flipping back and forth between threads as the enable/disable output stuff is flipped back and forth.
>
>
Great stuff! Actually one probably could apply similar optimization to
the SharedInputBuffer as well to reduce intermediate buffer copying for
input operations.
Oleg
Re: Async http client experiments....
Posted by Daniel Kulp <dk...@apache.org>.
On Sep 10, 2012, at 6:13 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> I think this problem can be easily fixed. If the expected X500Principal
> is known in advance, one can stick it into the local execution context
> as ClientContext#USER_TOKEN attribute [1]. This will force the client to
> request connections with the given state only.
Yep. Worked perfectly.
I committed my latest updates to the sandbox. A little more cleanup and I'll likely merge it into the main build.
I did do a pretty big update to the SharedOutputBuffer to better handle the case where a large byte[] is passed into the write method. It will now avoid copying blocks out of there into the buffer to then copy into the encoder. Avoids a bunch of copies. Also avoids a bunch of flipping back and forth between threads as the enable/disable output stuff is flipped back and forth.
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com
Re: Async http client experiments....
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Sun, 2012-09-09 at 08:14 -0400, Daniel Kulp wrote:
> On Sep 8, 2012, at 4:33 PM, Oleg Kalnichevski <ol...@apache.org> wrote:
> > I committed your patch with some minor tweaks. Please double-check.
> >
>
> Cool. Thanks. I'll take a look on Monday.
>
> > The fundamental problem here is that SSL connections set up on a per
> > request (or per client basis) when kept alive by the connection manager
> > can be later leased to another client thread with a different security
> > context if one is not careful.
>
> Actually, I'm struggling with the OPPOSITE problem with the Async client. The Async client stores the X500Principal as the "state" for the connection (which is great BTW). Thus, subsequent calls that don't provide a state will never re-use the connection. I need to do a little work to store the principal, but it all looks very doable. Hopefully will finish that up on Monday.
>
>
Hi Daniel
I think this problem can be easily fixed. If the expected X500Principal
is known in advance, one can stick it into the local execution context
as ClientContext#USER_TOKEN attribute [1]. This will force the client to
request connections with the given state only.
[1]
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/advanced.html#stateful_conn
> > We can cut as many BETA releases as needed and as often as needed. There
> > have been not that many changes since BETA2, so I would not rush BETA3,
> > but I'll call for a release vote as soon as you need it. What I am not
> > really comfortable committing myself to is any time frame for a GA
> > release.
>
> That's fine. As long as there are "releases" in the central repo, we can at least proceed. For performance reasons, the async transport likely won't be a default, but it will be available to those that may need it. Definitely don't push a beta3 yet (unless someone else really needs it) as I do want to verify more tests with it, check how it will work in OSGi, etc...
>
All right. Let's hold it off for a little while. Once you are sure no
more changes are needed let me know and I'll start the release process.
Cheers
Oleg
Re: Async http client experiments....
Posted by Daniel Kulp <dk...@apache.org>.
On Sep 8, 2012, at 4:33 PM, Oleg Kalnichevski <ol...@apache.org> wrote:
> I committed your patch with some minor tweaks. Please double-check.
>
Cool. Thanks. I'll take a look on Monday.
> The fundamental problem here is that SSL connections set up on a per
> request (or per client basis) when kept alive by the connection manager
> can be later leased to another client thread with a different security
> context if one is not careful.
Actually, I'm struggling with the OPPOSITE problem with the Async client. The Async client stores the X500Principal as the "state" for the connection (which is great BTW). Thus, subsequent calls that don't provide a state will never re-use the connection. I need to do a little work to store the principal, but it all looks very doable. Hopefully will finish that up on Monday.
> We can cut as many BETA releases as needed and as often as needed. There
> have been not that many changes since BETA2, so I would not rush BETA3,
> but I'll call for a release vote as soon as you need it. What I am not
> really comfortable committing myself to is any time frame for a GA
> release.
That's fine. As long as there are "releases" in the central repo, we can at least proceed. For performance reasons, the async transport likely won't be a default, but it will be available to those that may need it. Definitely don't push a beta3 yet (unless someone else really needs it) as I do want to verify more tests with it, check how it will work in OSGi, etc...
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com
Re: Async http client experiments....
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2012-09-07 at 12:53 -0400, Daniel Kulp wrote:
> On Sep 6, 2012, at 9:33 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
>
> > On Wed, 2012-09-05 at 10:49 -0400, Daniel Kulp wrote:
> >> Still not sure about the Proxy stuff at all, but that's likely because I don't know much about Proxies at all. I'll likely need to look more into what proxy stuff does on the wire.
> >>
> >>
> >
> > HTTP proxy support is not all that difficult _as long as_ support for
> > complex HTTP authentication schemes is not required. If you need to
> > support NTLM, Kerberos and the likes, expect a lot of grief and massive
> > scalp hair loss. HttpAsyncClient provides full support for HTTP proxies
> > and most commonly used authentication schemes but it is still considered
> > BETA quality. If you want to re-use CXF authentication code HttpCore
> > would give you more flexibility at the expense of having to write more
> > custom code. Otherwise you might want consider trying out
> > HttpAsyncClient.
>
> Looking at the proxy stuff, I really have no interest in re-inventing the wheel on this. :-) Thus, it does look like going with HttpAsyncClient may make the most sense. I started digging into this a bit, but ran into the SSL configured "per connection factory" issue that I had before. HOWEVER, this looks easily solvable with a simple patch to HttpAsyncClient. I've logged the issue and attached it to:
>
> https://issues.apache.org/jira/browse/HTTPASYNC-25
>
> Anyway, with the HttpAsyncClient stuff, the amount of code in CXF is SIGNIFICANTLY reduced. A LOT less duplicated code. That's good. However, we would need to have beta3 released pretty soon. Any ideas on what the plans are for beta3? If beta3 won't be soon, I'll likely go with what I have now and detect if the proxy is configured and force use of the old transport if it is. If it will be release real soon, I'll pursue using it. I do have all the systests/transports tests passing with the HttpAsyncClient based stuff, including the new proxy based tests I added yesterday.
>
> Thoughts?
>
Hi Daniel
I committed your patch with some minor tweaks. Please double-check.
The fundamental problem here is that SSL connections set up on a per
request (or per client basis) when kept alive by the connection manager
can be later leased to another client thread with a different security
context if one is not careful.
We can cut as many BETA releases as needed and as often as needed. There
have been not that many changes since BETA2, so I would not rush BETA3,
but I'll call for a release vote as soon as you need it. What I am not
really comfortable committing myself to is any time frame for a GA
release.
Oleg
Re: Async http client experiments....
Posted by Daniel Kulp <dk...@apache.org>.
On Sep 6, 2012, at 9:33 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Wed, 2012-09-05 at 10:49 -0400, Daniel Kulp wrote:
>> Still not sure about the Proxy stuff at all, but that's likely because I don't know much about Proxies at all. I'll likely need to look more into what proxy stuff does on the wire.
>>
>>
>
> HTTP proxy support is not all that difficult _as long as_ support for
> complex HTTP authentication schemes is not required. If you need to
> support NTLM, Kerberos and the likes, expect a lot of grief and massive
> scalp hair loss. HttpAsyncClient provides full support for HTTP proxies
> and most commonly used authentication schemes but it is still considered
> BETA quality. If you want to re-use CXF authentication code HttpCore
> would give you more flexibility at the expense of having to write more
> custom code. Otherwise you might want consider trying out
> HttpAsyncClient.
Looking at the proxy stuff, I really have no interest in re-inventing the wheel on this. :-) Thus, it does look like going with HttpAsyncClient may make the most sense. I started digging into this a bit, but ran into the SSL configured "per connection factory" issue that I had before. HOWEVER, this looks easily solvable with a simple patch to HttpAsyncClient. I've logged the issue and attached it to:
https://issues.apache.org/jira/browse/HTTPASYNC-25
Anyway, with the HttpAsyncClient stuff, the amount of code in CXF is SIGNIFICANTLY reduced. A LOT less duplicated code. That's good. However, we would need to have beta3 released pretty soon. Any ideas on what the plans are for beta3? If beta3 won't be soon, I'll likely go with what I have now and detect if the proxy is configured and force use of the old transport if it is. If it will be release real soon, I'll pursue using it. I do have all the systests/transports tests passing with the HttpAsyncClient based stuff, including the new proxy based tests I added yesterday.
Thoughts?
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com
Re: Async http client experiments....
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2012-09-05 at 10:49 -0400, Daniel Kulp wrote:
> On Sep 5, 2012, at 9:26 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
...
> >> 2) Lots of issues trying to associate the request with the connection at connection creation time. I needed information from the request in order to setup the SSL stuff. However, I had a LOT of issues trying to accomplish that. The only thing the ConnectionFactory gets it the IOSession. All that has in it is the HttpHost. The HttpHost is final. The connect occurs on a different thread so thread locals won't work. Also note that all the fields in SSLIOSession are final and private. Thus, I also couldn't find a way to delay the SSL setup stuff till later. Thus, I had to get the request/connection stuff associated up front. I ended up using a IdentityHashMap to associate the HttpHost with the request stuff, but it seemed very hacky.
> >>
> >> Not really sure what the right solution would be. My initial thought was to make HttpHost non-final so that I could subclass it with an CXFHttpHost or SSLHttpHost or something that would contain extra methods that I could call. Alternatively, add a "properties" map to HttpHost or similar that I could store additional stuff. Another option would be to have the IOSession passed to the factory also contain the "state" (if specified) as a property that could be queried.
> >>
> >
> > Just ditch HttpHost. You obviously need a richer class to represent
> > connection routes. HttpClient has HttpRoute class for that matter. You
> > probably should be using a custom class that also includes HTTP proxy
> > and SSL context bits specific to CXF.
> >
> > Does this help you in any way?
>
> Yep. Just feels like I have to subclass/override a lot of behavior from HC instead of "using" it.
Well, in a way this is intended. For better or worse HttpCore was always
meant to be a set of low level components one could re-use and extend to
build custom HTTP services, primarily HTTP proxies and gateways. For end
users we provide HttpClient and HttpAsyncClient modules that are based
on HttpCore and represent more 'out of the box' products.
> If HttpHost wasn't final, it would be so much more useful. Is there a particular reason why it has to be final?
>
There is no particular reason but this is the very first time some one
actually wanted to extend it. I cant help thinking aggregation would be
more appropriate here than extension.
> Still not sure about the Proxy stuff at all, but that's likely because I don't know much about Proxies at all. I'll likely need to look more into what proxy stuff does on the wire.
>
>
HTTP proxy support is not all that difficult _as long as_ support for
complex HTTP authentication schemes is not required. If you need to
support NTLM, Kerberos and the likes, expect a lot of grief and massive
scalp hair loss. HttpAsyncClient provides full support for HTTP proxies
and most commonly used authentication schemes but it is still considered
BETA quality. If you want to re-use CXF authentication code HttpCore
would give you more flexibility at the expense of having to write more
custom code. Otherwise you might want consider trying out
HttpAsyncClient.
Oleg
Re: Async http client experiments....
Posted by Daniel Kulp <dk...@apache.org>.
On Sep 5, 2012, at 9:26 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> HC connection pools distinguish between route info and connection state.
> Routes are immutable and are well known in advance. A route in its basic
> form is a scheme/host/port combo. At connection creation time only the
> route matters as all HTTP connections start out their life cycle as
> state-less per HTTP specification. In real life settings, however, HTTP
> connections may acquire certain state during their life-cycle, for
> instance, by serving a resource protected with a connection based auth
> scheme such as NTLM. So, the object that represents a state of a
> connection may need to be associated with the connection after it has
> already been created. SSL is similar. An HTTP connection can be created
> as plain and later get upgraded to TLS/SSL. If the target server
> requires the client to authenticate itself with a certificate, the
> connection becomes state-full after successful authentication only.
>
> Once a connection becomes state-full it can only be leased if requested
> with the same combination of route info and state. I believe this is the
> reason why you are getting a new SSL connection for each new HTTPS
> request. I guess the state object used in the lease request is not equal
> to that associated with the pool entry.
Well, I was actually getting the opposite. Since the "state" object wasn't stored anywhere, I was getting a single connection for all the SSL requests to a service/host and thus was ending up having the wrong credentials after the first connection. For now, I forced a dummy state object on there to force a new connection per request to avoid the security issue of wrong credentials. Once I figure all the state things out, this should fix itself.
> If in your case SSL context details are effectively a given, you should
> make then a part of the route info instead of the state. HC connection
> pools are designed to be able to use any arbitrary immutable class as a
> route info.
OK. Subclass AbstractNIOConnPool instead of using BasicNIOConnPool.
>> 2) Lots of issues trying to associate the request with the connection at connection creation time. I needed information from the request in order to setup the SSL stuff. However, I had a LOT of issues trying to accomplish that. The only thing the ConnectionFactory gets it the IOSession. All that has in it is the HttpHost. The HttpHost is final. The connect occurs on a different thread so thread locals won't work. Also note that all the fields in SSLIOSession are final and private. Thus, I also couldn't find a way to delay the SSL setup stuff till later. Thus, I had to get the request/connection stuff associated up front. I ended up using a IdentityHashMap to associate the HttpHost with the request stuff, but it seemed very hacky.
>>
>> Not really sure what the right solution would be. My initial thought was to make HttpHost non-final so that I could subclass it with an CXFHttpHost or SSLHttpHost or something that would contain extra methods that I could call. Alternatively, add a "properties" map to HttpHost or similar that I could store additional stuff. Another option would be to have the IOSession passed to the factory also contain the "state" (if specified) as a property that could be queried.
>>
>
> Just ditch HttpHost. You obviously need a richer class to represent
> connection routes. HttpClient has HttpRoute class for that matter. You
> probably should be using a custom class that also includes HTTP proxy
> and SSL context bits specific to CXF.
>
> Does this help you in any way?
Yep. Just feels like I have to subclass/override a lot of behavior from HC instead of "using" it. If HttpHost wasn't final, it would be so much more useful. Is there a particular reason why it has to be final?
Still not sure about the Proxy stuff at all, but that's likely because I don't know much about Proxies at all. I'll likely need to look more into what proxy stuff does on the wire.
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com
Re: Async http client experiments....
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2012-09-04 at 15:20 -0400, Daniel Kulp wrote:
> On Aug 6, 2012, at 10:43 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> >>>> CXF allows these to be configured on a per-client (and sometimes even
> >>>> per- request) basis. It looks like HC seems to have these on the
> >>>> connection factory.
> >>>
> >>> It does not have to be this way. Connections can start off as plain and
> >>> later get upgraded to TLS/SSL by the protocol handling code. One would
> >>> have to tweak the default protocol handler a bit, though, probably by
> >>> overriding the HttpAsyncRequestExecutor#requestReady method [2].
> >>
> >> Ah. OK. I'll take a look there. I was looking in the various connection
> >> factories and pools. Haven't looked there yet. Lots of stuff going on.
> >> :-)
> >>
> >
> > I also added a CXF specific connection manager implementation in order
> > to enable SSL customization based on request configuration. However,
> > before I proceed I would like to understand the requirements a little
> > better. Can I assume that once an SSL connection has been fully set up
> > using request level config parameters and can be pooled and safely
> > reused for subsequent requests to the same service (even by different
> > users) or requests may contain different / incompatible SSL
> > configuration for the same service?
>
> They may contain different configurations. Particular different client certs if using client certs as the authentication mechanism.
>
> I found the "state" object to pass into the connection factory and plan on implementing a new state object that will attempt to handle that by comparing the various values on the HTTPConduit settings. However, I *DID* run into a couple problems that, while I was able to work around them with some hacks, they likely should be fixed in the HTTP stuff. In particular:
>
> 1) The "state" object that is passed into the factory is never saved anywhere. IMO, if a new connection is created based on the state, it might be good to record that state (or at least make that an option) so the state stuff actually works. I got around this by subclassing the BasicNIOConnPool to override the BasicNIOConnPool.createEntry method to add a state object to the entry. A bit involved.
>
Let me try to explain the rationale behind the design.
HC connection pools distinguish between route info and connection state.
Routes are immutable and are well known in advance. A route in its basic
form is a scheme/host/port combo. At connection creation time only the
route matters as all HTTP connections start out their life cycle as
state-less per HTTP specification. In real life settings, however, HTTP
connections may acquire certain state during their life-cycle, for
instance, by serving a resource protected with a connection based auth
scheme such as NTLM. So, the object that represents a state of a
connection may need to be associated with the connection after it has
already been created. SSL is similar. An HTTP connection can be created
as plain and later get upgraded to TLS/SSL. If the target server
requires the client to authenticate itself with a certificate, the
connection becomes state-full after successful authentication only.
Once a connection becomes state-full it can only be leased if requested
with the same combination of route info and state. I believe this is the
reason why you are getting a new SSL connection for each new HTTPS
request. I guess the state object used in the lease request is not equal
to that associated with the pool entry.
If in your case SSL context details are effectively a given, you should
make then a part of the route info instead of the state. HC connection
pools are designed to be able to use any arbitrary immutable class as a
route info.
> 2) Lots of issues trying to associate the request with the connection at connection creation time. I needed information from the request in order to setup the SSL stuff. However, I had a LOT of issues trying to accomplish that. The only thing the ConnectionFactory gets it the IOSession. All that has in it is the HttpHost. The HttpHost is final. The connect occurs on a different thread so thread locals won't work. Also note that all the fields in SSLIOSession are final and private. Thus, I also couldn't find a way to delay the SSL setup stuff till later. Thus, I had to get the request/connection stuff associated up front. I ended up using a IdentityHashMap to associate the HttpHost with the request stuff, but it seemed very hacky.
>
> Not really sure what the right solution would be. My initial thought was to make HttpHost non-final so that I could subclass it with an CXFHttpHost or SSLHttpHost or something that would contain extra methods that I could call. Alternatively, add a "properties" map to HttpHost or similar that I could store additional stuff. Another option would be to have the IOSession passed to the factory also contain the "state" (if specified) as a property that could be queried.
>
Just ditch HttpHost. You obviously need a richer class to represent
connection routes. HttpClient has HttpRoute class for that matter. You
probably should be using a custom class that also includes HTTP proxy
and SSL context bits specific to CXF.
Does this help you in any way?
Oleg
Re: Async http client experiments....
Posted by Daniel Kulp <dk...@apache.org>.
On Aug 6, 2012, at 10:43 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
>>>> CXF allows these to be configured on a per-client (and sometimes even
>>>> per- request) basis. It looks like HC seems to have these on the
>>>> connection factory.
>>>
>>> It does not have to be this way. Connections can start off as plain and
>>> later get upgraded to TLS/SSL by the protocol handling code. One would
>>> have to tweak the default protocol handler a bit, though, probably by
>>> overriding the HttpAsyncRequestExecutor#requestReady method [2].
>>
>> Ah. OK. I'll take a look there. I was looking in the various connection
>> factories and pools. Haven't looked there yet. Lots of stuff going on.
>> :-)
>>
>
> I also added a CXF specific connection manager implementation in order
> to enable SSL customization based on request configuration. However,
> before I proceed I would like to understand the requirements a little
> better. Can I assume that once an SSL connection has been fully set up
> using request level config parameters and can be pooled and safely
> reused for subsequent requests to the same service (even by different
> users) or requests may contain different / incompatible SSL
> configuration for the same service?
They may contain different configurations. Particular different client certs if using client certs as the authentication mechanism.
I found the "state" object to pass into the connection factory and plan on implementing a new state object that will attempt to handle that by comparing the various values on the HTTPConduit settings. However, I *DID* run into a couple problems that, while I was able to work around them with some hacks, they likely should be fixed in the HTTP stuff. In particular:
1) The "state" object that is passed into the factory is never saved anywhere. IMO, if a new connection is created based on the state, it might be good to record that state (or at least make that an option) so the state stuff actually works. I got around this by subclassing the BasicNIOConnPool to override the BasicNIOConnPool.createEntry method to add a state object to the entry. A bit involved.
2) Lots of issues trying to associate the request with the connection at connection creation time. I needed information from the request in order to setup the SSL stuff. However, I had a LOT of issues trying to accomplish that. The only thing the ConnectionFactory gets it the IOSession. All that has in it is the HttpHost. The HttpHost is final. The connect occurs on a different thread so thread locals won't work. Also note that all the fields in SSLIOSession are final and private. Thus, I also couldn't find a way to delay the SSL setup stuff till later. Thus, I had to get the request/connection stuff associated up front. I ended up using a IdentityHashMap to associate the HttpHost with the request stuff, but it seemed very hacky.
Not really sure what the right solution would be. My initial thought was to make HttpHost non-final so that I could subclass it with an CXFHttpHost or SSLHttpHost or something that would contain extra methods that I could call. Alternatively, add a "properties" map to HttpHost or similar that I could store additional stuff. Another option would be to have the IOSession passed to the factory also contain the "state" (if specified) as a property that could be queried.
Anyway, things are definitely in "ok" shape right now. Definitely making some significant progress. Slowly but surely.
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com
Re: Async http client experiments....
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2012-09-06 at 10:12 -0400, Daniel Kulp wrote:
> On Sep 6, 2012, at 9:40 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> > On Wed, 2012-09-05 at 10:55 -0400, Daniel Kulp wrote:
> >> On Sep 5, 2012, at 9:35 AM, Alessio Soldano <as...@redhat.com> wrote:
> >>
> >>> On 09/04/2012 09:03 PM, Daniel Kulp wrote:
> >>>>
> >>>> That said, there is still a bit of work todo:
> >>>>
> >>>> 1) Proxy support - haven't looked into this at all yet. Hard for me to test as well as I don't have any sort of proxy setup anywhere. I may need to look into how to setup a simple proxy to dig into this.
> >>>
> >>> Not sure if this would be the best option for you, but some time ago I
> >>> wrote some JBossWS tests related to http proxy configuration by using
> >>> LittleProxy [1], perhaps it's convenient here too.
> >>>
> >>> [1] http://www.littleshoot.org/littleproxy/
> >>
> >> Cool. I see they just started a vote for 0.5 so if I wait a day or three, I can just start with the newer version. :-)
> >>
> >> Thanks for the pointer.
> >>
> >> Dan
> >>
> >
> > I personally use Squid [1] running locally in non-daemon mode to test
> > HttpClient against. It is one of the most widely used proxies around.
>
>
> I was originally looking at this, but there is a big disadvantage: it's external to the build. The nice thing about the littleproxy thing is in your junit tests, you can pop up a proxy on any port, use it, bring it down, etc… just like any other service we may be using. It would work on every developers machine.
>
> Right now, we have ZERO coverage of the proxy support in CXF, even for the HttpURLConnection based transport. With the little proxy thing, I'm hoping to rectify that. That said, I don't think it provides all the various possible proxy situations that squid can, but at this point, some tests are better than none. :-)
>
>
This is certainly a very valid point. Actually we are in the same boat.
Close to zero coverage of proxy code. And we have all the building
blocks necessary to put together a full blown caching proxy. The trouble
is that the _real_ troublemaker is never the proxy itself. In most cases
proxies are almost transparent to the client. The real ugly b**ch is
always a combination of HTTP proxy and authentication (either on the
proxy or the target side), especially NTLM, which is not very easy to
emulate.
Oleg
Re: Async http client experiments....
Posted by Alessio Soldano <as...@redhat.com>.
On 09/06/2012 04:12 PM, Daniel Kulp wrote:
>>
>> I personally use Squid [1] running locally in non-daemon mode to test
>> HttpClient against. It is one of the most widely used proxies around.
>
>
> I was originally looking at this, but there is a big disadvantage: it's external to the build. The nice thing about the littleproxy thing is in your junit tests, you can pop up a proxy on any port, use it, bring it down, etc… just like any other service we may be using. It would work on every developers machine.
+100, exactly my reasoning
Alessio
--
Alessio Soldano
Web Service Lead, JBoss
Re: Async http client experiments....
Posted by Daniel Kulp <dk...@apache.org>.
On Sep 6, 2012, at 9:40 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Wed, 2012-09-05 at 10:55 -0400, Daniel Kulp wrote:
>> On Sep 5, 2012, at 9:35 AM, Alessio Soldano <as...@redhat.com> wrote:
>>
>>> On 09/04/2012 09:03 PM, Daniel Kulp wrote:
>>>>
>>>> That said, there is still a bit of work todo:
>>>>
>>>> 1) Proxy support - haven't looked into this at all yet. Hard for me to test as well as I don't have any sort of proxy setup anywhere. I may need to look into how to setup a simple proxy to dig into this.
>>>
>>> Not sure if this would be the best option for you, but some time ago I
>>> wrote some JBossWS tests related to http proxy configuration by using
>>> LittleProxy [1], perhaps it's convenient here too.
>>>
>>> [1] http://www.littleshoot.org/littleproxy/
>>
>> Cool. I see they just started a vote for 0.5 so if I wait a day or three, I can just start with the newer version. :-)
>>
>> Thanks for the pointer.
>>
>> Dan
>>
>
> I personally use Squid [1] running locally in non-daemon mode to test
> HttpClient against. It is one of the most widely used proxies around.
I was originally looking at this, but there is a big disadvantage: it's external to the build. The nice thing about the littleproxy thing is in your junit tests, you can pop up a proxy on any port, use it, bring it down, etc… just like any other service we may be using. It would work on every developers machine.
Right now, we have ZERO coverage of the proxy support in CXF, even for the HttpURLConnection based transport. With the little proxy thing, I'm hoping to rectify that. That said, I don't think it provides all the various possible proxy situations that squid can, but at this point, some tests are better than none. :-)
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com
Re: Async http client experiments....
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2012-09-05 at 10:55 -0400, Daniel Kulp wrote:
> On Sep 5, 2012, at 9:35 AM, Alessio Soldano <as...@redhat.com> wrote:
>
> > On 09/04/2012 09:03 PM, Daniel Kulp wrote:
> >>
> >> That said, there is still a bit of work todo:
> >>
> >> 1) Proxy support - haven't looked into this at all yet. Hard for me to test as well as I don't have any sort of proxy setup anywhere. I may need to look into how to setup a simple proxy to dig into this.
> >
> > Not sure if this would be the best option for you, but some time ago I
> > wrote some JBossWS tests related to http proxy configuration by using
> > LittleProxy [1], perhaps it's convenient here too.
> >
> > [1] http://www.littleshoot.org/littleproxy/
>
> Cool. I see they just started a vote for 0.5 so if I wait a day or three, I can just start with the newer version. :-)
>
> Thanks for the pointer.
>
> Dan
>
I personally use Squid [1] running locally in non-daemon mode to test
HttpClient against. It is one of the most widely used proxies around.
Oleg
[1] http://en.wikipedia.org/wiki/Squid_%28software%29
> >
> > Cheers
> > Alessio
> >
> > --
> > Alessio Soldano
> > Web Service Lead, JBoss
>
Re: Async http client experiments....
Posted by Daniel Kulp <dk...@apache.org>.
On Sep 5, 2012, at 9:35 AM, Alessio Soldano <as...@redhat.com> wrote:
> On 09/04/2012 09:03 PM, Daniel Kulp wrote:
>>
>> That said, there is still a bit of work todo:
>>
>> 1) Proxy support - haven't looked into this at all yet. Hard for me to test as well as I don't have any sort of proxy setup anywhere. I may need to look into how to setup a simple proxy to dig into this.
>
> Not sure if this would be the best option for you, but some time ago I
> wrote some JBossWS tests related to http proxy configuration by using
> LittleProxy [1], perhaps it's convenient here too.
>
> [1] http://www.littleshoot.org/littleproxy/
Cool. I see they just started a vote for 0.5 so if I wait a day or three, I can just start with the newer version. :-)
Thanks for the pointer.
Dan
>
> Cheers
> Alessio
>
> --
> Alessio Soldano
> Web Service Lead, JBoss
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com
Re: Async http client experiments....
Posted by Alessio Soldano <as...@redhat.com>.
On 09/04/2012 09:03 PM, Daniel Kulp wrote:
>
> That said, there is still a bit of work todo:
>
> 1) Proxy support - haven't looked into this at all yet. Hard for me to test as well as I don't have any sort of proxy setup anywhere. I may need to look into how to setup a simple proxy to dig into this.
Not sure if this would be the best option for you, but some time ago I
wrote some JBossWS tests related to http proxy configuration by using
LittleProxy [1], perhaps it's convenient here too.
[1] http://www.littleshoot.org/littleproxy/
Cheers
Alessio
--
Alessio Soldano
Web Service Lead, JBoss
Re: Async http client experiments....
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2012-09-04 at 15:03 -0400, Daniel Kulp wrote:
> Finally had a chance over the last week or so to re-dig into the async http stuff. You've probably seen a lot of commits and such related to it. :-)
>
> Good news:
> ALL of the CXF system tests now pass using it instead of the URLConnection based transport. I'm pretty excited about that as that's a huge milestone.
>
Hi Dan
I am glad things are shaping up well.
> That said, there is still a bit of work todo:
>
> 1) Proxy support - haven't looked into this at all yet. Hard for me to test as well as I don't have any sort of proxy setup anywhere. I may need to look into how to setup a simple proxy to dig into this.
>
> 2) HTTPs Keep-Alive - right now, with HTTPs, a new connect is created for every request. With HTTPs, that's really expensive as it needs to do the handshakes and such for every request. This is next on my TODO to look at. One issue is that the BasicNIOConnPool really only compares the host name/port/scheme to determine connection re-use. Not any of the certs or anything like that. I'll need to implement a "state" object to handle checking a lot of that. Definitely next.
>
> 3) Configuration - now that things are working, I'll need to find a way to expose some configuration things. Specifically around things like number of connections to hold open, number per target/host, thread pools, etc….
>
> 4) Flip the logging and such to using our normal Logging framework.
>
> 5) Move it all from the sandbox to trunk.
>
>
> Anyway, definitely getting closer. :-)
>
I am completely buried under with work at my day job (the one that helps
me pay the bills) and am unlikely to be able to find a lot of time to
write code but will happily assist with HC specific issues. Just let me
know.
Cheers
Oleg
>
> Dan
>
>
>
> On Aug 6, 2012, at 10:43 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
>
> > On Fri, 2012-08-03 at 09:17 -0400, Daniel Kulp wrote:
> >> On Friday, August 03, 2012 11:29:41 AM Oleg Kalnichevski wrote:
> >>>> I just went through and added a little bit of error handling into it as
> >>>> well. Mostly around a connection refused exception and for read
> >>>> timeouts. For the read timeout, I DID have to add an ioct.shutdown() in
> >>>> the SharedInBuffer consume method when read or it kept getting called
> >>>> repeatedly since we didn't read anything.
> >>>
> >>> Hmmm. This should not be necessary. It is the responsibility of the
> >>> protocol handler to shut down things properly if connection goes down or
> >>> something breaks at runtime. In case of an I/O timeout the protocol
> >>> handler always shuts down the execution handler, which in its turn
> >>> should shut down shared i/o buffers [1]. I'll look into it.
> >>
> >> Well, it's mostly because I didn't actually set the timeouts on the
> >> connection at all. Haven't figured that out yet mostly due to the same
> >> issus as with the SSL/connection timeouts/etc... as we set them on a per-
> >> request basis normally. For now so things don't "hang", I just added
> >> timeouts on the wait(...) calls we use when we need to block for additional
> >> IO. In that case, the wait(...) times out and I need to shutdown the
> >> buffers and such manually so when the data DOES eventually arrive, we ignore
> >> it. Setting the "real" timeouts on the connections would definitely help.
> >>
> >
> >
> > Hi Daniel
> >
> > I tweaked the code a bit to make sure i/o timeouts (both connect and
> > receive ones) are handled correctly and can be specified on a per
> > request basis overriding the defaults. Please review / verify.
> >
> > I also added connection pool lease / release logging. I am no longer
> > seeing anything suspicious related to connection management. When
> > executing requests sequentially the connection manager allocates one
> > connection only.
> >
> >>>> CXF allows these to be configured on a per-client (and sometimes even
> >>>> per- request) basis. It looks like HC seems to have these on the
> >>>> connection factory.
> >>>
> >>> It does not have to be this way. Connections can start off as plain and
> >>> later get upgraded to TLS/SSL by the protocol handling code. One would
> >>> have to tweak the default protocol handler a bit, though, probably by
> >>> overriding the HttpAsyncRequestExecutor#requestReady method [2].
> >>
> >> Ah. OK. I'll take a look there. I was looking in the various connection
> >> factories and pools. Haven't looked there yet. Lots of stuff going on.
> >> :-)
> >>
> >
> > I also added a CXF specific connection manager implementation in order
> > to enable SSL customization based on request configuration. However,
> > before I proceed I would like to understand the requirements a little
> > better. Can I assume that once an SSL connection has been fully set up
> > using request level config parameters and can be pooled and safely
> > reused for subsequent requests to the same service (even by different
> > users) or requests may contain different / incompatible SSL
> > configuration for the same service?
> >
> > Oleg
> >
> >
>
Re: Async http client experiments....
Posted by Daniel Kulp <dk...@apache.org>.
Finally had a chance over the last week or so to re-dig into the async http stuff. You've probably seen a lot of commits and such related to it. :-)
Good news:
ALL of the CXF system tests now pass using it instead of the URLConnection based transport. I'm pretty excited about that as that's a huge milestone.
That said, there is still a bit of work todo:
1) Proxy support - haven't looked into this at all yet. Hard for me to test as well as I don't have any sort of proxy setup anywhere. I may need to look into how to setup a simple proxy to dig into this.
2) HTTPs Keep-Alive - right now, with HTTPs, a new connect is created for every request. With HTTPs, that's really expensive as it needs to do the handshakes and such for every request. This is next on my TODO to look at. One issue is that the BasicNIOConnPool really only compares the host name/port/scheme to determine connection re-use. Not any of the certs or anything like that. I'll need to implement a "state" object to handle checking a lot of that. Definitely next.
3) Configuration - now that things are working, I'll need to find a way to expose some configuration things. Specifically around things like number of connections to hold open, number per target/host, thread pools, etc….
4) Flip the logging and such to using our normal Logging framework.
5) Move it all from the sandbox to trunk.
Anyway, definitely getting closer. :-)
Dan
On Aug 6, 2012, at 10:43 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Fri, 2012-08-03 at 09:17 -0400, Daniel Kulp wrote:
>> On Friday, August 03, 2012 11:29:41 AM Oleg Kalnichevski wrote:
>>>> I just went through and added a little bit of error handling into it as
>>>> well. Mostly around a connection refused exception and for read
>>>> timeouts. For the read timeout, I DID have to add an ioct.shutdown() in
>>>> the SharedInBuffer consume method when read or it kept getting called
>>>> repeatedly since we didn't read anything.
>>>
>>> Hmmm. This should not be necessary. It is the responsibility of the
>>> protocol handler to shut down things properly if connection goes down or
>>> something breaks at runtime. In case of an I/O timeout the protocol
>>> handler always shuts down the execution handler, which in its turn
>>> should shut down shared i/o buffers [1]. I'll look into it.
>>
>> Well, it's mostly because I didn't actually set the timeouts on the
>> connection at all. Haven't figured that out yet mostly due to the same
>> issus as with the SSL/connection timeouts/etc... as we set them on a per-
>> request basis normally. For now so things don't "hang", I just added
>> timeouts on the wait(...) calls we use when we need to block for additional
>> IO. In that case, the wait(...) times out and I need to shutdown the
>> buffers and such manually so when the data DOES eventually arrive, we ignore
>> it. Setting the "real" timeouts on the connections would definitely help.
>>
>
>
> Hi Daniel
>
> I tweaked the code a bit to make sure i/o timeouts (both connect and
> receive ones) are handled correctly and can be specified on a per
> request basis overriding the defaults. Please review / verify.
>
> I also added connection pool lease / release logging. I am no longer
> seeing anything suspicious related to connection management. When
> executing requests sequentially the connection manager allocates one
> connection only.
>
>>>> CXF allows these to be configured on a per-client (and sometimes even
>>>> per- request) basis. It looks like HC seems to have these on the
>>>> connection factory.
>>>
>>> It does not have to be this way. Connections can start off as plain and
>>> later get upgraded to TLS/SSL by the protocol handling code. One would
>>> have to tweak the default protocol handler a bit, though, probably by
>>> overriding the HttpAsyncRequestExecutor#requestReady method [2].
>>
>> Ah. OK. I'll take a look there. I was looking in the various connection
>> factories and pools. Haven't looked there yet. Lots of stuff going on.
>> :-)
>>
>
> I also added a CXF specific connection manager implementation in order
> to enable SSL customization based on request configuration. However,
> before I proceed I would like to understand the requirements a little
> better. Can I assume that once an SSL connection has been fully set up
> using request level config parameters and can be pooled and safely
> reused for subsequent requests to the same service (even by different
> users) or requests may contain different / incompatible SSL
> configuration for the same service?
>
> Oleg
>
>
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com
Re: Async http client experiments....
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2012-08-03 at 09:17 -0400, Daniel Kulp wrote:
> On Friday, August 03, 2012 11:29:41 AM Oleg Kalnichevski wrote:
> > > I just went through and added a little bit of error handling into it as
> > > well. Mostly around a connection refused exception and for read
> > > timeouts. For the read timeout, I DID have to add an ioct.shutdown() in
> > > the SharedInBuffer consume method when read or it kept getting called
> > > repeatedly since we didn't read anything.
> >
> > Hmmm. This should not be necessary. It is the responsibility of the
> > protocol handler to shut down things properly if connection goes down or
> > something breaks at runtime. In case of an I/O timeout the protocol
> > handler always shuts down the execution handler, which in its turn
> > should shut down shared i/o buffers [1]. I'll look into it.
>
> Well, it's mostly because I didn't actually set the timeouts on the
> connection at all. Haven't figured that out yet mostly due to the same
> issus as with the SSL/connection timeouts/etc... as we set them on a per-
> request basis normally. For now so things don't "hang", I just added
> timeouts on the wait(...) calls we use when we need to block for additional
> IO. In that case, the wait(...) times out and I need to shutdown the
> buffers and such manually so when the data DOES eventually arrive, we ignore
> it. Setting the "real" timeouts on the connections would definitely help.
>
Hi Daniel
I tweaked the code a bit to make sure i/o timeouts (both connect and
receive ones) are handled correctly and can be specified on a per
request basis overriding the defaults. Please review / verify.
I also added connection pool lease / release logging. I am no longer
seeing anything suspicious related to connection management. When
executing requests sequentially the connection manager allocates one
connection only.
> > > CXF allows these to be configured on a per-client (and sometimes even
> > > per- request) basis. It looks like HC seems to have these on the
> > > connection factory.
> >
> > It does not have to be this way. Connections can start off as plain and
> > later get upgraded to TLS/SSL by the protocol handling code. One would
> > have to tweak the default protocol handler a bit, though, probably by
> > overriding the HttpAsyncRequestExecutor#requestReady method [2].
>
> Ah. OK. I'll take a look there. I was looking in the various connection
> factories and pools. Haven't looked there yet. Lots of stuff going on.
> :-)
>
I also added a CXF specific connection manager implementation in order
to enable SSL customization based on request configuration. However,
before I proceed I would like to understand the requirements a little
better. Can I assume that once an SSL connection has been fully set up
using request level config parameters and can be pooled and safely
reused for subsequent requests to the same service (even by different
users) or requests may contain different / incompatible SSL
configuration for the same service?
Oleg
Re: Async http client experiments....
Posted by Daniel Kulp <dk...@apache.org>.
On Friday, August 03, 2012 11:29:41 AM Oleg Kalnichevski wrote:
> > I just went through and added a little bit of error handling into it as
> > well. Mostly around a connection refused exception and for read
> > timeouts. For the read timeout, I DID have to add an ioct.shutdown() in
> > the SharedInBuffer consume method when read or it kept getting called
> > repeatedly since we didn't read anything.
>
> Hmmm. This should not be necessary. It is the responsibility of the
> protocol handler to shut down things properly if connection goes down or
> something breaks at runtime. In case of an I/O timeout the protocol
> handler always shuts down the execution handler, which in its turn
> should shut down shared i/o buffers [1]. I'll look into it.
Well, it's mostly because I didn't actually set the timeouts on the
connection at all. Haven't figured that out yet mostly due to the same
issus as with the SSL/connection timeouts/etc... as we set them on a per-
request basis normally. For now so things don't "hang", I just added
timeouts on the wait(...) calls we use when we need to block for additional
IO. In that case, the wait(...) times out and I need to shutdown the
buffers and such manually so when the data DOES eventually arrive, we ignore
it. Setting the "real" timeouts on the connections would definitely help.
> > CXF allows these to be configured on a per-client (and sometimes even
> > per- request) basis. It looks like HC seems to have these on the
> > connection factory.
>
> It does not have to be this way. Connections can start off as plain and
> later get upgraded to TLS/SSL by the protocol handling code. One would
> have to tweak the default protocol handler a bit, though, probably by
> overriding the HttpAsyncRequestExecutor#requestReady method [2].
Ah. OK. I'll take a look there. I was looking in the various connection
factories and pools. Haven't looked there yet. Lots of stuff going on.
:-)
Dan
>
> > I thought about a new factory per request, but the pool seems to
> >
> > be tied to the connection factory as well and a full pool per request
> > would be aweful. I then wanted to see if I could pass some sort of
> > contextual object in (there is that BasicHttpContext object) that I
> > could pull information out of at connection time or similar, but I
> > could really figure out where that went, at least not until after the
> > IOSession is setup, which is too late. Also thought about a thread
> > local, but that doesn't work with the async connection.
>
> I'll try to find time to write all the necessary plumbing code on this
> weekend.
>
> Cheers
>
> Oleg
>
> > Any ideas on that would be a huge help. I'll keep digging a bit as
> > well.
> > Kind of learning more about the HC stuff and NIO and all kind of things,
> > which is kind of fun. :-)
>
> [1]
> http://hc.apache.org/httpcomponents-core-ga/httpcore-nio/xref/org/apache/h
> ttp/nio/protocol/HttpAsyncRequestExecutor.html#269 [2]
> http://hc.apache.org/httpcomponents-core-ga/httpcore-nio/xref/org/apache/h
> ttp/nio/protocol/HttpAsyncRequestExecutor.html#124
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com
Re: Async http client experiments....
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2012-08-02 at 14:58 -0400, Daniel Kulp wrote:
> On Wednesday, August 01, 2012 05:58:23 PM Oleg Kalnichevski wrote:
> > Hi Daniel
...
>
> > I also noticed that for some reason additional connections get open and
> > closed without transmitting any data, which obviously should not be
> > happening. I'll investigate the problem if you confirm that you want me
> > to proceed.
>
> Interesting. I'm actually not seeing that now. :-) I ran the testCalls
> things with small and larger requests and in both cases, all 20K requests
> went on a single connection. Was quite impressed. (I actually expected the
> Jetty backend to have a limit on number of requests per keepalive as I ran
> into a similar setting in Tomcat last week that defaulted to 100).
>
I would like to investigate nonetheless. Besides, connection pool
logging might come handy in other situations as well.
> I just went through and added a little bit of error handling into it as
> well. Mostly around a connection refused exception and for read timeouts.
> For the read timeout, I DID have to add an ioct.shutdown() in the
> SharedInBuffer consume method when read or it kept getting called repeatedly
> since we didn't read anything.
>
Hmmm. This should not be necessary. It is the responsibility of the
protocol handler to shut down things properly if connection goes down or
something breaks at runtime. In case of an I/O timeout the protocol
handler always shuts down the execution handler, which in its turn
should shut down shared i/o buffers [1]. I'll look into it.
> Also started working on the resends and such, but haven't yet added a
> testcase for that.
>
> So, stuff I have left to look at are basically: (and I've add //FIXME
> comments in the code where I *think* something needs to happen)
>
> 1) Proxy support
> 2) SSL/TLS
> 3) Connection timeouts
>
Connect timeouts, i/o timeouts, TLS/SSL layering should be supported out
of the box. Proxy support can present a certain conceptual challenge as
it automatically implies a decision as to whether or not HTTP
authentication is to be supported and if so to what extent. Complex auth
schemes such SPNEGO and NTLM entail a lot of additional complexity and
may require additional external dependencies. HC provide full support
for HTTP request proxying and HTTPS tunneling in its higher level
components (HttpClient and HttpAsyncClient) but not in core. So, the
options are to upgrade to HttpAsyncClient or to implement proxy support
in the CXF HTTP conduit. The former most likely means having to live
with different (potentially inconsistent) HTTP authentication
frameworks. The latter means having more flexibility at the price of
having more code to maintain. So, essentially it is a classic buy
(re-use) or build dilemma.
> CXF allows these to be configured on a per-client (and sometimes even per-
> request) basis. It looks like HC seems to have these on the connection
> factory.
It does not have to be this way. Connections can start off as plain and
later get upgraded to TLS/SSL by the protocol handling code. One would
have to tweak the default protocol handler a bit, though, probably by
overriding the HttpAsyncRequestExecutor#requestReady method [2].
> I thought about a new factory per request, but the pool seems to
> be tied to the connection factory as well and a full pool per request would
> be aweful. I then wanted to see if I could pass some sort of contextual
> object in (there is that BasicHttpContext object) that I could pull
> information out of at connection time or similar, but I could really figure
> out where that went, at least not until after the IOSession is setup, which
> is too late. Also thought about a thread local, but that doesn't work with
> the async connection.
>
I'll try to find time to write all the necessary plumbing code on this
weekend.
Cheers
Oleg
> Any ideas on that would be a huge help. I'll keep digging a bit as well.
> Kind of learning more about the HC stuff and NIO and all kind of things,
> which is kind of fun. :-)
>
>
[1]
http://hc.apache.org/httpcomponents-core-ga/httpcore-nio/xref/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.html#269
[2]
http://hc.apache.org/httpcomponents-core-ga/httpcore-nio/xref/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.html#124
Re: Async http client experiments....
Posted by Daniel Kulp <dk...@apache.org>.
On Wednesday, August 01, 2012 05:58:23 PM Oleg Kalnichevski wrote:
> Hi Daniel
>
> I believe I have fixed the thread synchronization issue. All tests
> repeatedly passed for me. Could you please have a look at my changes and
> confirm that everything is more or less sane and HTTP transport still
> performs at an acceptable level?
Finally got a chance to look at all the stuff you did. Awesome work!
> As the next I could optimize the code and hopefully bring its
> performance closer to that of the default blocking transport.
>
> I also noticed that for some reason additional connections get open and
> closed without transmitting any data, which obviously should not be
> happening. I'll investigate the problem if you confirm that you want me
> to proceed.
Interesting. I'm actually not seeing that now. :-) I ran the testCalls
things with small and larger requests and in both cases, all 20K requests
went on a single connection. Was quite impressed. (I actually expected the
Jetty backend to have a limit on number of requests per keepalive as I ran
into a similar setting in Tomcat last week that defaulted to 100).
I just went through and added a little bit of error handling into it as
well. Mostly around a connection refused exception and for read timeouts.
For the read timeout, I DID have to add an ioct.shutdown() in the
SharedInBuffer consume method when read or it kept getting called repeatedly
since we didn't read anything.
Also started working on the resends and such, but haven't yet added a
testcase for that.
So, stuff I have left to look at are basically: (and I've add //FIXME
comments in the code where I *think* something needs to happen)
1) Proxy support
2) SSL/TLS
3) Connection timeouts
CXF allows these to be configured on a per-client (and sometimes even per-
request) basis. It looks like HC seems to have these on the connection
factory. I thought about a new factory per request, but the pool seems to
be tied to the connection factory as well and a full pool per request would
be aweful. I then wanted to see if I could pass some sort of contextual
object in (there is that BasicHttpContext object) that I could pull
information out of at connection time or similar, but I could really figure
out where that went, at least not until after the IOSession is setup, which
is too late. Also thought about a thread local, but that doesn't work with
the async connection.
Any ideas on that would be a huge help. I'll keep digging a bit as well.
Kind of learning more about the HC stuff and NIO and all kind of things,
which is kind of fun. :-)
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com