You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Ruwan Linton <ru...@gmail.com> on 2010/04/06 09:29:38 UTC

Closing the persisted server connections on IOReactor pause

Hi Devs,

We (Synapse) has a requirement to close the persisted connections
(keep-alive) when the IOReactor is being paused, and I have looked at the
code and tried to get hold of all the persisted connections that are being
used at the time of the IOReactor pause, without any success :-(

1) Is it possible to do this?
2) If so, can you please point me to a code snippet or class or a method to
have a look at in getting all the keep-alive connections?

Thanks,
Ruwan

-- 
Ruwan Linton
Technical Lead & Product Manager; WSO2 ESB; http://wso2.org/esb
WSO2 Inc.; http://wso2.org
email: ruwan@wso2.com; cell: +94 77 341 3097
blog: http://ruwansblog.blogspot.com

Re: Closing the persisted server connections on IOReactor pause

Posted by Ruwan Linton <ru...@gmail.com>.
Hi Oleg



> It was a conscious decision to provide only very basic protocol handlers
> out of the box in HttpCore, primarily to not be seen as competition to
> other Apache projects. This probably is no longer relevant. So, If
> anyone would be willing to work on improving protocol handlers in
> HttpCore, I could happily offer my assistance.
>
> However, a better approach might be building an embeddable mini HTTP
> server based on HttpCore with proper connection/thread management and
> keep HttpCore what it is, just core.
>

I agree! Then from our point of view it is best to maintain the code for
managing the connections in the synapse nhttp transport itself. Sorry I am
still picking the httpcore design, and didn't realize that connection
management is out of the scope of the httpcore :-(

Anyway, thanks a lot for the big help.

Thanks,
Ruwan


>
> Cheers
>
> Oleg
>
> > BTW: really appreciate your help in getting this resolved.
> >
> > Thanks,
> > Ruwan
> >
> > On Thu, Apr 22, 2010 at 5:59 PM, Oleg Kalnichevski <ol...@apache.org>
> wrote:
> >
> > > On Thu, 2010-04-22 at 16:10 +0530, Ruwan Linton wrote:
> > > > Oleg,
> > > >
> > > > I wrote the code, expecting that the IOControl#requestOutput will be
> > > calling
> > > > the NhttpServiceHandler#outputReady method or the
> > > > NhttpServiceHandler#responseReady method, but non of those get
> called?
> > > >
> > > > Do you have any clue or is it a different method that I should be
> > > expected
> > > > be calling by the IOReactor??
> > > >
> > >
> > >
> > > NhttpServiceHandler#responseReady event should fire in response to the
> > > IOControl#requestOutput. Synapse trunk has extensive logging support
> for
> > > HTTP wire and context logging. Try turning it on to get more details on
> > > what is happening inside the NHTTP transport.
> > >
> > > Oleg
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> > > For additional commands, e-mail: dev-help@hc.apache.org
> > >
> > >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>



-- 
Ruwan Linton
Technical Lead & Product Manager; WSO2 ESB; http://wso2.org/esb
WSO2 Inc.; http://wso2.org
email: ruwan@wso2.com; cell: +94 77 341 3097
blog: http://ruwansblog.blogspot.com

Re: Closing the persisted server connections on IOReactor pause

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Sun, 2010-04-25 at 22:00 +0530, Ruwan Linton wrote:
> Hi Oleg,
> 
> Thanks a lot, I have got it fixed.
> 

Hi Ruwan

I am glad I was of some help

> Moving forward, do you think that this can be incooperated with the
> IOReactor#pause??

Ideally I/O reactors should remain protocol agnostic. They should deal
with I/O sessions, not with HTTP connections. Connection management
should be the responsibility of protocol handlers. 

> 
> Why I am saying this is, IOReactor#pause should make sure that the server is
> not accepting any more messages, right? but if you have keep-alive turned
> on, those persisted connections will be used by the clients to continue
> sending messages, since the IOReactor#pause doesn't close the persisted
> connections.
> 
> WDYT?
> 

It was a conscious decision to provide only very basic protocol handlers
out of the box in HttpCore, primarily to not be seen as competition to
other Apache projects. This probably is no longer relevant. So, If
anyone would be willing to work on improving protocol handlers in
HttpCore, I could happily offer my assistance. 

However, a better approach might be building an embeddable mini HTTP
server based on HttpCore with proper connection/thread management and
keep HttpCore what it is, just core. 

Cheers

Oleg

> BTW: really appreciate your help in getting this resolved.
> 
> Thanks,
> Ruwan
> 
> On Thu, Apr 22, 2010 at 5:59 PM, Oleg Kalnichevski <ol...@apache.org> wrote:
> 
> > On Thu, 2010-04-22 at 16:10 +0530, Ruwan Linton wrote:
> > > Oleg,
> > >
> > > I wrote the code, expecting that the IOControl#requestOutput will be
> > calling
> > > the NhttpServiceHandler#outputReady method or the
> > > NhttpServiceHandler#responseReady method, but non of those get called?
> > >
> > > Do you have any clue or is it a different method that I should be
> > expected
> > > be calling by the IOReactor??
> > >
> >
> >
> > NhttpServiceHandler#responseReady event should fire in response to the
> > IOControl#requestOutput. Synapse trunk has extensive logging support for
> > HTTP wire and context logging. Try turning it on to get more details on
> > what is happening inside the NHTTP transport.
> >
> > Oleg
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> > For additional commands, e-mail: dev-help@hc.apache.org
> >
> >
> 
> 



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


Re: Closing the persisted server connections on IOReactor pause

Posted by Ruwan Linton <ru...@gmail.com>.
Hi Oleg,

Thanks a lot, I have got it fixed.

Moving forward, do you think that this can be incooperated with the
IOReactor#pause??

Why I am saying this is, IOReactor#pause should make sure that the server is
not accepting any more messages, right? but if you have keep-alive turned
on, those persisted connections will be used by the clients to continue
sending messages, since the IOReactor#pause doesn't close the persisted
connections.

WDYT?

BTW: really appreciate your help in getting this resolved.

Thanks,
Ruwan

On Thu, Apr 22, 2010 at 5:59 PM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Thu, 2010-04-22 at 16:10 +0530, Ruwan Linton wrote:
> > Oleg,
> >
> > I wrote the code, expecting that the IOControl#requestOutput will be
> calling
> > the NhttpServiceHandler#outputReady method or the
> > NhttpServiceHandler#responseReady method, but non of those get called?
> >
> > Do you have any clue or is it a different method that I should be
> expected
> > be calling by the IOReactor??
> >
>
>
> NhttpServiceHandler#responseReady event should fire in response to the
> IOControl#requestOutput. Synapse trunk has extensive logging support for
> HTTP wire and context logging. Try turning it on to get more details on
> what is happening inside the NHTTP transport.
>
> Oleg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>


-- 
Ruwan Linton
Technical Lead & Product Manager; WSO2 ESB; http://wso2.org/esb
WSO2 Inc.; http://wso2.org
email: ruwan@wso2.com; cell: +94 77 341 3097
blog: http://ruwansblog.blogspot.com

Re: Closing the persisted server connections on IOReactor pause

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2010-04-22 at 16:10 +0530, Ruwan Linton wrote:
> Oleg,
> 
> I wrote the code, expecting that the IOControl#requestOutput will be calling
> the NhttpServiceHandler#outputReady method or the
> NhttpServiceHandler#responseReady method, but non of those get called?
> 
> Do you have any clue or is it a different method that I should be expected
> be calling by the IOReactor??
> 


NhttpServiceHandler#responseReady event should fire in response to the
IOControl#requestOutput. Synapse trunk has extensive logging support for
HTTP wire and context logging. Try turning it on to get more details on
what is happening inside the NHTTP transport.

Oleg


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


Re: Closing the persisted server connections on IOReactor pause

Posted by Ruwan Linton <ru...@gmail.com>.
Oleg,

I wrote the code, expecting that the IOControl#requestOutput will be calling
the NhttpServiceHandler#outputReady method or the
NhttpServiceHandler#responseReady method, but non of those get called?

Do you have any clue or is it a different method that I should be expected
be calling by the IOReactor??

Thanks,
Ruwan

On Sun, Apr 18, 2010 at 7:51 PM, Ruwan Linton <ru...@gmail.com>wrote:

>
>
> On Sun, Apr 18, 2010 at 4:17 PM, Oleg Kalnichevski <ol...@apache.org>wrote:
>
>> On Sun, 2010-04-18 at 08:00 +0530, Ruwan Linton wrote:
>> > Hi Oleg,
>> >
>> >
>> > > Hi Ruwan
>> > >
>> > > You have got to be very careful here. HTTP connection objects are not
>> > > thread safe! One can easily run into a race condition when interacting
>> > > with connection objects from any other but an I/O dispatch thread.
>> > >
>> >
>> > I have already encountered the above issue, and had a look at the
>> > NhttpConnection class JavaDoc and realized this.
>> >
>> >
>> > >
>> > > So, Here is the recommended way of going about this problem. You
>> should
>> > > signal the intention to terminate the connection by setting a special
>> > > attribute in the session context or changing the state of the shared
>> > > connection state object and let the connection shut down itself, when
>> it
>> > > is done processing the actual message.
>> >
>> >
>> > Thanks a lot for this valuable input, I was thinking how I can proceed
>> with
>> > my limited knowledge on httpcore. Really appreciate this help.
>> >
>> >
>> > > If the persistent connection is
>> > > idle, you may need to active it by using the IOControl interface.
>> > >
>> >
>> > May be I didn't get this part, could you please tell me how to check
>> whether
>> > the connection is idle or not?
>> >
>>
>> Hi Ruwan
>>
>> There is simply no reliable way to test that. By the time you are done
>> checking, the connection may finish message processing and become idle.
>> So, what you should do it to update the connection state (for instance,
>> in this particular case, by setting a termination request flag),
>> activate the connection by requesting output processing with
>> IOControl#requestOutput and let the connection react to the changed
>> state.
>>
>> Hope this helps
>>
>
> Of course, this helps a lot.
>
> I will get back to you with the status of my work, as soon as I am done
> with it, or will post any issues I get along the path.
>
> Thanks a lot for the excellent help.
>
> Ruwan
>
>
>>
>> Oleg
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
>> For additional commands, e-mail: dev-help@hc.apache.org
>>
>>
>
>
> --
> Ruwan Linton
> Technical Lead & Product Manager; WSO2 ESB; http://wso2.org/esb
> WSO2 Inc.; http://wso2.org
> email: ruwan@wso2.com; cell: +94 77 341 3097
> blog: http://ruwansblog.blogspot.com
>



-- 
Ruwan Linton
Technical Lead & Product Manager; WSO2 ESB; http://wso2.org/esb
WSO2 Inc.; http://wso2.org
email: ruwan@wso2.com; cell: +94 77 341 3097
blog: http://ruwansblog.blogspot.com

Re: Closing the persisted server connections on IOReactor pause

Posted by Ruwan Linton <ru...@gmail.com>.
On Sun, Apr 18, 2010 at 4:17 PM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Sun, 2010-04-18 at 08:00 +0530, Ruwan Linton wrote:
> > Hi Oleg,
> >
> >
> > > Hi Ruwan
> > >
> > > You have got to be very careful here. HTTP connection objects are not
> > > thread safe! One can easily run into a race condition when interacting
> > > with connection objects from any other but an I/O dispatch thread.
> > >
> >
> > I have already encountered the above issue, and had a look at the
> > NhttpConnection class JavaDoc and realized this.
> >
> >
> > >
> > > So, Here is the recommended way of going about this problem. You should
> > > signal the intention to terminate the connection by setting a special
> > > attribute in the session context or changing the state of the shared
> > > connection state object and let the connection shut down itself, when
> it
> > > is done processing the actual message.
> >
> >
> > Thanks a lot for this valuable input, I was thinking how I can proceed
> with
> > my limited knowledge on httpcore. Really appreciate this help.
> >
> >
> > > If the persistent connection is
> > > idle, you may need to active it by using the IOControl interface.
> > >
> >
> > May be I didn't get this part, could you please tell me how to check
> whether
> > the connection is idle or not?
> >
>
> Hi Ruwan
>
> There is simply no reliable way to test that. By the time you are done
> checking, the connection may finish message processing and become idle.
> So, what you should do it to update the connection state (for instance,
> in this particular case, by setting a termination request flag),
> activate the connection by requesting output processing with
> IOControl#requestOutput and let the connection react to the changed
> state.
>
> Hope this helps
>

Of course, this helps a lot.

I will get back to you with the status of my work, as soon as I am done with
it, or will post any issues I get along the path.

Thanks a lot for the excellent help.

Ruwan


>
> Oleg
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>


-- 
Ruwan Linton
Technical Lead & Product Manager; WSO2 ESB; http://wso2.org/esb
WSO2 Inc.; http://wso2.org
email: ruwan@wso2.com; cell: +94 77 341 3097
blog: http://ruwansblog.blogspot.com

Re: Closing the persisted server connections on IOReactor pause

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Sun, 2010-04-18 at 08:00 +0530, Ruwan Linton wrote:
> Hi Oleg,
> 
> 
> > Hi Ruwan
> >
> > You have got to be very careful here. HTTP connection objects are not
> > thread safe! One can easily run into a race condition when interacting
> > with connection objects from any other but an I/O dispatch thread.
> >
> 
> I have already encountered the above issue, and had a look at the
> NhttpConnection class JavaDoc and realized this.
> 
> 
> >
> > So, Here is the recommended way of going about this problem. You should
> > signal the intention to terminate the connection by setting a special
> > attribute in the session context or changing the state of the shared
> > connection state object and let the connection shut down itself, when it
> > is done processing the actual message.
> 
> 
> Thanks a lot for this valuable input, I was thinking how I can proceed with
> my limited knowledge on httpcore. Really appreciate this help.
> 
> 
> > If the persistent connection is
> > idle, you may need to active it by using the IOControl interface.
> >
> 
> May be I didn't get this part, could you please tell me how to check whether
> the connection is idle or not?
> 

Hi Ruwan

There is simply no reliable way to test that. By the time you are done
checking, the connection may finish message processing and become idle.
So, what you should do it to update the connection state (for instance,
in this particular case, by setting a termination request flag),
activate the connection by requesting output processing with
IOControl#requestOutput and let the connection react to the changed
state.

Hope this helps

Oleg




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


Re: Closing the persisted server connections on IOReactor pause

Posted by Ruwan Linton <ru...@gmail.com>.
Hi Oleg,


> Hi Ruwan
>
> You have got to be very careful here. HTTP connection objects are not
> thread safe! One can easily run into a race condition when interacting
> with connection objects from any other but an I/O dispatch thread.
>

I have already encountered the above issue, and had a look at the
NhttpConnection class JavaDoc and realized this.


>
> So, Here is the recommended way of going about this problem. You should
> signal the intention to terminate the connection by setting a special
> attribute in the session context or changing the state of the shared
> connection state object and let the connection shut down itself, when it
> is done processing the actual message.


Thanks a lot for this valuable input, I was thinking how I can proceed with
my limited knowledge on httpcore. Really appreciate this help.


> If the persistent connection is
> idle, you may need to active it by using the IOControl interface.
>

May be I didn't get this part, could you please tell me how to check whether
the connection is idle or not?


>
>
> http://hc.apache.org/httpcomponents-core-4.0.1/tutorial/html/nio.html#d0e1301
>


Thanks,
Ruwan


>
> Hope this helps
>
> Oleg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>



-- 
Ruwan Linton
Technical Lead & Product Manager; WSO2 ESB; http://wso2.org/esb
WSO2 Inc.; http://wso2.org
email: ruwan@wso2.com; cell: +94 77 341 3097
blog: http://ruwansblog.blogspot.com

Re: Closing the persisted server connections on IOReactor pause

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Sat, 2010-04-17 at 09:03 +0530, Ruwan Linton wrote:
> Hi Oleg,
> 
> I was able to get hold of the server side connection pool with using a list
> and recording them using the above mentioned methods.
> 
> Now I was trying to check the condition, whether a connection is being used
> or not at a given point in time. Meaning that whether this particular
> connection has a message in-flight at the given instance, could you help me
> on figuring out that condition as well?
> 
> Checking both, getHttpRequest and getHttpResponse to be null will work, if
> my understanding of the code is correct, but is there a better way to check
> the above condition?
> 

Hi Ruwan

You have got to be very careful here. HTTP connection objects are not
thread safe! One can easily run into a race condition when interacting
with connection objects from any other but an I/O dispatch thread.

So, Here is the recommended way of going about this problem. You should
signal the intention to terminate the connection by setting a special
attribute in the session context or changing the state of the shared
connection state object and let the connection shut down itself, when it
is done processing the actual message. If the persistent connection is
idle, you may need to active it by using the IOControl interface.

http://hc.apache.org/httpcomponents-core-4.0.1/tutorial/html/nio.html#d0e1301

Hope this helps

Oleg


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


Re: Closing the persisted server connections on IOReactor pause

Posted by Ruwan Linton <ru...@gmail.com>.
Hi Oleg,

I was able to get hold of the server side connection pool with using a list
and recording them using the above mentioned methods.

Now I was trying to check the condition, whether a connection is being used
or not at a given point in time. Meaning that whether this particular
connection has a message in-flight at the given instance, could you help me
on figuring out that condition as well?

Checking both, getHttpRequest and getHttpResponse to be null will work, if
my understanding of the code is correct, but is there a better way to check
the above condition?

Thanks in advance,
Ruwan

On Thu, Apr 15, 2010 at 9:05 PM, Ruwan Linton <ru...@gmail.com>wrote:

> Hi Oleg,
>
> Sorry for the late response, I was on a vacation. I will try this and get
> back to you with the result.
>
> Thanks a lot for the help.
>
> Thanks,
> Ruwan
>
>
> On Tue, Apr 6, 2010 at 6:02 PM, Oleg Kalnichevski <ol...@apache.org>wrote:
>
>> On Tue, 2010-04-06 at 12:59 +0530, Ruwan Linton wrote:
>> > Hi Devs,
>> >
>> > We (Synapse) has a requirement to close the persisted connections
>> > (keep-alive) when the IOReactor is being paused, and I have looked at
>> the
>> > code and tried to get hold of all the persisted connections that are
>> being
>> > used at the time of the IOReactor pause, without any success :-(
>> >
>> > 1) Is it possible to do this?
>>
>> Yes, it is.
>>
>> > 2) If so, can you please point me to a code snippet or class or a method
>> to
>> > have a look at in getting all the keep-alive connections?
>> >
>>
>> You should be using #connected and #disconnected methods of
>> NHttpClientHandler / NHttpServerHandler interfaces to keep track of open
>> HTTP connections.
>>
>> Hope this helps
>>
>> Oleg
>>
>>
>> > Thanks,
>> > Ruwan
>> >
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
>> For additional commands, e-mail: dev-help@hc.apache.org
>>
>>
>
>
> --
> Ruwan Linton
> Technical Lead & Product Manager; WSO2 ESB; http://wso2.org/esb
> WSO2 Inc.; http://wso2.org
> email: ruwan@wso2.com; cell: +94 77 341 3097
> blog: http://ruwansblog.blogspot.com
>



-- 
Ruwan Linton
Technical Lead & Product Manager; WSO2 ESB; http://wso2.org/esb
WSO2 Inc.; http://wso2.org
email: ruwan@wso2.com; cell: +94 77 341 3097
blog: http://ruwansblog.blogspot.com

Re: Closing the persisted server connections on IOReactor pause

Posted by Ruwan Linton <ru...@gmail.com>.
Hi Oleg,

Sorry for the late response, I was on a vacation. I will try this and get
back to you with the result.

Thanks a lot for the help.

Thanks,
Ruwan

On Tue, Apr 6, 2010 at 6:02 PM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Tue, 2010-04-06 at 12:59 +0530, Ruwan Linton wrote:
> > Hi Devs,
> >
> > We (Synapse) has a requirement to close the persisted connections
> > (keep-alive) when the IOReactor is being paused, and I have looked at the
> > code and tried to get hold of all the persisted connections that are
> being
> > used at the time of the IOReactor pause, without any success :-(
> >
> > 1) Is it possible to do this?
>
> Yes, it is.
>
> > 2) If so, can you please point me to a code snippet or class or a method
> to
> > have a look at in getting all the keep-alive connections?
> >
>
> You should be using #connected and #disconnected methods of
> NHttpClientHandler / NHttpServerHandler interfaces to keep track of open
> HTTP connections.
>
> Hope this helps
>
> Oleg
>
>
> > Thanks,
> > Ruwan
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>


-- 
Ruwan Linton
Technical Lead & Product Manager; WSO2 ESB; http://wso2.org/esb
WSO2 Inc.; http://wso2.org
email: ruwan@wso2.com; cell: +94 77 341 3097
blog: http://ruwansblog.blogspot.com

Re: Closing the persisted server connections on IOReactor pause

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2010-04-06 at 12:59 +0530, Ruwan Linton wrote:
> Hi Devs,
> 
> We (Synapse) has a requirement to close the persisted connections
> (keep-alive) when the IOReactor is being paused, and I have looked at the
> code and tried to get hold of all the persisted connections that are being
> used at the time of the IOReactor pause, without any success :-(
> 
> 1) Is it possible to do this?

Yes, it is.

> 2) If so, can you please point me to a code snippet or class or a method to
> have a look at in getting all the keep-alive connections?
> 

You should be using #connected and #disconnected methods of
NHttpClientHandler / NHttpServerHandler interfaces to keep track of open
HTTP connections. 

Hope this helps

Oleg


> Thanks,
> Ruwan
> 



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