You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Hanson Char <ha...@gmail.com> on 2006/08/06 00:28:16 UTC

Graceful Shutdown ?

Hi,

I am interested in your thoughts and suggestions in implementing a
graceful shutdown of a Mina server.  Please read below for details.

Hanson Char

Implementing Graceful Shutdown
========================
We have a server implemented in Mina 0.8.2, and are thinking of
implementing a graceful shutdown of the server upon certain event
(such as trapping a SIGINT or SIGTERM).

The shutdown basically needs to:
1) stop any new connection from being made, and
2) closes all existing open sessions;

For (2), however, I am thinking instead of closing the outstanding
open sessions immediately, maybe a better approach would be to wait
for the existing write's to finish prior to closing the sessions ?

Specifically, for each existing open session,
1) check if it is idle and if so close the session immediately;
2) if not, wait for up to 10 seconds (or whatever timeout parameter),
or until it's idle, then close the session;

Thoughts ?  Suggestions ?

Thanks in advance.

Re: Graceful Shutdown ?

Posted by peter royal <pr...@apache.org>.
On Aug 11, 2006, at 3:05 AM, Maarten Bosteels wrote:
> Lately I have seen several posts from you and Peter recommending  
> people
> to use 0.9.x because it's a lot better than 0.8.x - which I am  
> prepared to
> believe.
> I think the FAQ needs an update, it states:
> "Prefer the latest release with even version numbers to with odd  
> ones."
>
> I personnaly I don't like the even/odd versioning scheme. I think a  
> lot of
> new MINA users
> are still starting with the latest 0.8 release because it is called
> "stable".
> They will all have considerable conversion work when switching to  
> 0.9 (or
> 1.0)

I have updated the faq in svn, and will try to get the site deployed  
soonish.

As for the even/odd scheme, I'm open to changing how versioning is  
done, but that'd be a post-1.0 task :)

-pete


-- 
proyal@apache.org - http://fotap.org/~osi




Re: Graceful Shutdown ?

Posted by Maarten Bosteels <mb...@gmail.com>.
Trustin,

Is this suggestion specific for 0.8.x or does it also apply to 0.9.4 and up
?

Lately I have seen several posts from you and Peter recommending people
to use 0.9.x because it's a lot better than 0.8.x - which I am prepared to
believe.
I think the FAQ needs an update, it states:
"Prefer the latest release with even version numbers to with odd ones."

I personnaly I don't like the even/odd versioning scheme. I think a lot of
new MINA users
are still starting with the latest 0.8 release because it is called
"stable".
They will all have considerable conversion work when switching to 0.9 (or
1.0)

Maarten

On 8/11/06, Trustin Lee <tr...@gmail.com> wrote:
>
> Here's my suggestion on graceful shutdown.
>
> 1) Modify your I/O Handler (or ProtocolHandler) to maintain the list of
> connected sessions.  sessionOpened() and sessionClosed() would be the best
> place to do this.
> 2) Unbind the service so there cannot be more new sessions.  The existing
> sessions will not be disconnected at this moment.
> 3) Close all sessions in the list you've been maintaining at step (1).
>
> Regarding the timeout stuff, it depends on the contract between clients
> and
> a server, so the implementation can change depending on it.  My suggestion
> is just to close the sessions immediately because a server that takes
> minutes to shut itself down makes administrators unhappy.
>
> HTH,
> Trustin
>
> On 8/6/06, Hanson Char <ha...@gmail.com> wrote:
> >
> > Hi,
> >
> > I am interested in your thoughts and suggestions in implementing a
> > graceful shutdown of a Mina server.  Please read below for details.
> >
> > Hanson Char
> >
> > Implementing Graceful Shutdown
> > ========================
> > We have a server implemented in Mina 0.8.2, and are thinking of
> > implementing a graceful shutdown of the server upon certain event
> > (such as trapping a SIGINT or SIGTERM).
> >
> > The shutdown basically needs to:
> > 1) stop any new connection from being made, and
> > 2) closes all existing open sessions;
> >
> > For (2), however, I am thinking instead of closing the outstanding
> > open sessions immediately, maybe a better approach would be to wait
> > for the existing write's to finish prior to closing the sessions ?
> >
> > Specifically, for each existing open session,
> > 1) check if it is idle and if so close the session immediately;
> > 2) if not, wait for up to 10 seconds (or whatever timeout parameter),
> > or until it's idle, then close the session;
> >
> > Thoughts ?  Suggestions ?
> >
> > Thanks in advance.
> >
>
>
>
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP key fingerprints:
> * E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
> * B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6
>
>

Re: Graceful Shutdown ?

Posted by Hanson Char <ha...@gmail.com>.
> > "Unbinds from the specified address and disconnects all clients
> > connected there."

Is it true that this only applies to Mina 0.9.4, not 0.8.2 ?  In other
words, in Mina 0.8.2, the unbind does NOT disconnect all connected
clients.  Right ?

Hanson

On 8/11/06, Maarten Bosteels <mb...@gmail.com> wrote:
> see IoAcceptorConfig:
> http://directory.apache.org/subprojects/mina/apidocs/org/apache/mina/common/IoAcceptorConfig.html#setDisconnectOnUnbind(boolean)
>
> Maarten
>
> On 8/11/06, Michael Bauroth <mi...@falcom.de> wrote:
> >
> > Hi,
> >
> > a short question about point 2:
> >
> > How can I realize this unbind? When I call for the acceptor the
> > unbindAll() or unbind(...), in the code documentation I find the hint:
> >
> > "Unbinds from the specified address and disconnects all clients
> > connected there."
> >
> > Regards
> > Michael
> >
> > Trustin Lee wrote:
> > > Here's my suggestion on graceful shutdown.
> > >
> > > 1) Modify your I/O Handler (or ProtocolHandler) to maintain the list of
> > > connected sessions.  sessionOpened() and sessionClosed() would be the
> > best
> > > place to do this.
> > > 2) Unbind the service so there cannot be more new sessions.  The
> > existing
> > > sessions will not be disconnected at this moment.
> > > 3) Close all sessions in the list you've been maintaining at step (1).
> >
>
>

Re: Graceful Shutdown ?

Posted by Michael Bauroth <mi...@falcom.de>.
Oh, I see ;)

thank you.
Michael

Maarten Bosteels wrote:
> see IoAcceptorConfig:
> http://directory.apache.org/subprojects/mina/apidocs/org/apache/mina/common/IoAcceptorConfig.html#setDisconnectOnUnbind(boolean) 
> 
> 
> Maarten

Re: Graceful Shutdown ?

Posted by Maarten Bosteels <mb...@gmail.com>.
see IoAcceptorConfig:
http://directory.apache.org/subprojects/mina/apidocs/org/apache/mina/common/IoAcceptorConfig.html#setDisconnectOnUnbind(boolean)

Maarten

On 8/11/06, Michael Bauroth <mi...@falcom.de> wrote:
>
> Hi,
>
> a short question about point 2:
>
> How can I realize this unbind? When I call for the acceptor the
> unbindAll() or unbind(...), in the code documentation I find the hint:
>
> "Unbinds from the specified address and disconnects all clients
> connected there."
>
> Regards
> Michael
>
> Trustin Lee wrote:
> > Here's my suggestion on graceful shutdown.
> >
> > 1) Modify your I/O Handler (or ProtocolHandler) to maintain the list of
> > connected sessions.  sessionOpened() and sessionClosed() would be the
> best
> > place to do this.
> > 2) Unbind the service so there cannot be more new sessions.  The
> existing
> > sessions will not be disconnected at this moment.
> > 3) Close all sessions in the list you've been maintaining at step (1).
>

Re: Graceful Shutdown ?

Posted by Michael Bauroth <mi...@falcom.de>.
Hi,

a short question about point 2:

How can I realize this unbind? When I call for the acceptor the 
unbindAll() or unbind(...), in the code documentation I find the hint:

"Unbinds from the specified address and disconnects all clients 
connected there."

Regards
Michael

Trustin Lee wrote:
> Here's my suggestion on graceful shutdown.
> 
> 1) Modify your I/O Handler (or ProtocolHandler) to maintain the list of
> connected sessions.  sessionOpened() and sessionClosed() would be the best
> place to do this.
> 2) Unbind the service so there cannot be more new sessions.  The existing
> sessions will not be disconnected at this moment.
> 3) Close all sessions in the list you've been maintaining at step (1).

Re: Graceful Shutdown ?

Posted by Hanson Char <ha...@gmail.com>.
Hi Trustin,

Thanks for your suggestions.  Coincidentally, we have implemented (1),
(2), and (3), along with other stuff, very similar to what you
suggested !  (Actually I may as well change them to behave exactly as
you suggested ...)

As to (4), we are using the Java 5 ScheduledExecutorService framework
to allow those active connections to continue for about 10 seconds
before forcefully shutting them down.  Hopefully the administrators
won't be too unhappy about this :)

As to the use of Mina 0.9.4+ vs 0.8.2, the only concern, however
pathetic, is that 0.8.2 is under the "stable" directory, whereas 0.9.4
is under "unstable".  Since we are deploying the app to some dead
serious production environment....Any chance the 0.9.4 can be moved
under "stable", so we can move on to it without causing unnecessary
concerns to the admin/management group ?

H


On 8/10/06, Trustin Lee <tr...@gmail.com> wrote:
> Here's my suggestion on graceful shutdown.
>
> 1) Modify your I/O Handler (or ProtocolHandler) to maintain the list of
> connected sessions.  sessionOpened() and sessionClosed() would be the best
> place to do this.
> 2) Unbind the service so there cannot be more new sessions.  The existing
> sessions will not be disconnected at this moment.
> 3) Close all sessions in the list you've been maintaining at step (1).
>
> Regarding the timeout stuff, it depends on the contract between clients and
> a server, so the implementation can change depending on it.  My suggestion
> is just to close the sessions immediately because a server that takes
> minutes to shut itself down makes administrators unhappy.
>
> HTH,
> Trustin
>
> On 8/6/06, Hanson Char <ha...@gmail.com> wrote:
> >
> > Hi,
> >
> > I am interested in your thoughts and suggestions in implementing a
> > graceful shutdown of a Mina server.  Please read below for details.
> >
> > Hanson Char
> >
> > Implementing Graceful Shutdown
> > ========================
> > We have a server implemented in Mina 0.8.2, and are thinking of
> > implementing a graceful shutdown of the server upon certain event
> > (such as trapping a SIGINT or SIGTERM).
> >
> > The shutdown basically needs to:
> > 1) stop any new connection from being made, and
> > 2) closes all existing open sessions;
> >
> > For (2), however, I am thinking instead of closing the outstanding
> > open sessions immediately, maybe a better approach would be to wait
> > for the existing write's to finish prior to closing the sessions ?
> >
> > Specifically, for each existing open session,
> > 1) check if it is idle and if so close the session immediately;
> > 2) if not, wait for up to 10 seconds (or whatever timeout parameter),
> > or until it's idle, then close the session;
> >
> > Thoughts ?  Suggestions ?
> >
> > Thanks in advance.
> >
>
>
>
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP key fingerprints:
> * E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
> * B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6
>
>

Re: Graceful Shutdown ?

Posted by Trustin Lee <tr...@gmail.com>.
Here's my suggestion on graceful shutdown.

1) Modify your I/O Handler (or ProtocolHandler) to maintain the list of
connected sessions.  sessionOpened() and sessionClosed() would be the best
place to do this.
2) Unbind the service so there cannot be more new sessions.  The existing
sessions will not be disconnected at this moment.
3) Close all sessions in the list you've been maintaining at step (1).

Regarding the timeout stuff, it depends on the contract between clients and
a server, so the implementation can change depending on it.  My suggestion
is just to close the sessions immediately because a server that takes
minutes to shut itself down makes administrators unhappy.

HTH,
Trustin

On 8/6/06, Hanson Char <ha...@gmail.com> wrote:
>
> Hi,
>
> I am interested in your thoughts and suggestions in implementing a
> graceful shutdown of a Mina server.  Please read below for details.
>
> Hanson Char
>
> Implementing Graceful Shutdown
> ========================
> We have a server implemented in Mina 0.8.2, and are thinking of
> implementing a graceful shutdown of the server upon certain event
> (such as trapping a SIGINT or SIGTERM).
>
> The shutdown basically needs to:
> 1) stop any new connection from being made, and
> 2) closes all existing open sessions;
>
> For (2), however, I am thinking instead of closing the outstanding
> open sessions immediately, maybe a better approach would be to wait
> for the existing write's to finish prior to closing the sessions ?
>
> Specifically, for each existing open session,
> 1) check if it is idle and if so close the session immediately;
> 2) if not, wait for up to 10 seconds (or whatever timeout parameter),
> or until it's idle, then close the session;
>
> Thoughts ?  Suggestions ?
>
> Thanks in advance.
>



-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6

Re: Graceful Shutdown ?

Posted by Hanson Char <ha...@gmail.com>.
Question: in Mina 0.8.2, does

  Session.close(true);

waits for all outstanding asyn write operations to complete before
closing the session ?

If so, maybe I can wrap the invocation of each

  session.close(true);

within the execution of a thread that has a timeout if, and only if,
timeout happens, invoke

  session.close();

It would be nice if there was a method like

  Session.close(int timeout);

which waits for the close to finish up to the timeout limit.

Hanson

On 8/5/06, Hanson Char <ha...@gmail.com> wrote:
> Hi,
>
> I am interested in your thoughts and suggestions in implementing a
> graceful shutdown of a Mina server.  Please read below for details.
>
> Hanson Char
>
> Implementing Graceful Shutdown
> ========================
> We have a server implemented in Mina 0.8.2, and are thinking of
> implementing a graceful shutdown of the server upon certain event
> (such as trapping a SIGINT or SIGTERM).
>
> The shutdown basically needs to:
> 1) stop any new connection from being made, and
> 2) closes all existing open sessions;
>
> For (2), however, I am thinking instead of closing the outstanding
> open sessions immediately, maybe a better approach would be to wait
> for the existing write's to finish prior to closing the sessions ?
>
> Specifically, for each existing open session,
> 1) check if it is idle and if so close the session immediately;
> 2) if not, wait for up to 10 seconds (or whatever timeout parameter),
> or until it's idle, then close the session;
>
> Thoughts ?  Suggestions ?
>
> Thanks in advance.
>