You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by haiyun wang <fo...@gmail.com> on 2007/02/19 19:13:06 UTC

How to detect the client disconnection

Hi all,

I currently use mina as the Gateway and something works fine. However, I
found out a problem.
1) When the client unpluged the cable, how the server knows? I think server
can't detect it. But how to find out the send message fail on certain
sesssion.
2) BTW, which value should I use as a socket session ID? Currently i use
sessionIO.hashcode. Any better idea?
3) If I send the 10000 message to one of the session at the same time, would
that block the message deliever to the other sessions?


Thanks.

Re: How to detect the client disconnection

Posted by Trustin Lee <tr...@gmail.com>.
2007-02-25 (일), 02:42 +0800, mat 쓰시길:
> Thanks for your answer.
> 
> 1) My question is how to detect my write() is failed. MINA has this
> function?

If you write a message, IoSession.write() returns a WriteFuture.  You
can add a listener that handles an exception there.  You will also get
notified in your exceptionCaught() implementation.  A connection is
closed automatically when an IOException is caught, so you don't need to
do any further operation to close a connection.

> 2) Can you kindly show me how you generate your session ID? Right now i use
> session.hashcode, do you think it is good?

int sessionId = System.identityHashCode(session);

> 3) I am just newbie about the newworking programming. So can you point out
> the way to measure CPU time for  the I/O wait? What you said if my server
> side bandwidth is small, the situation I discribe could happen?

If you write faster than what your network can acceptor, MINA will store
your write requests in an internal queue.  If there are too many queued
requests, you will get OutOfMemoryError.  You need to control the write
throughput by yourself using methods such as
IoSession.getQueuedWriteReqeusts().

> 4) How can I prevent the client open millions of socket connection to my
> server and try to crash my server?

First, you need to be able to detect if the server is overloaded.  Once
detected, you can close any incoming connection or limit the number of
incoming messages by controlling the traffic of each session.

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: How to detect the client disconnection

Posted by mat <fo...@gmail.com>.
Thanks for your answer.

1) My question is how to detect my write() is failed. MINA has this
function?
2) Can you kindly show me how you generate your session ID? Right now i use
session.hashcode, do you think it is good?
3) I am just newbie about the newworking programming. So can you point out
the way to measure CPU time for  the I/O wait? What you said if my server
side bandwidth is small, the situation I discribe could happen?
4) How can I prevent the client open millions of socket connection to my
server and try to crash my server?
Thanks again.


2007/2/23, Vinod Panicker <vi...@gmail.com>:
>
> On 2/21/07, mat <fo...@gmail.com> wrote:
> > Thanks. Please see *** for reply
> >
> > 2007/2/20, Trustin Lee <tr...@gmail.com>:
> > >
> > > 2007-02-20 (화), 02:13 +0800, haiyun wang 쓰시길:
> > > > Hi all,
> > > >
> > > > I currently use mina as the Gateway and something works fine.
> However, I
> > > > found out a problem.
> > > > 1) When the client unpluged the cable, how the server knows? I think
> > > server
> > > > can't detect it. But how to find out the send message fail on
> certain
> > > > sesssion.
> > >
> > > The bottom line is that server doesn't know and you get to know that
> > > when you write something.  Please refer to this thread:
> > >
> > > http://tinyurl.com/2wzznb
> >
> >
> > *** Can you kindly point out how to detect write something on session
> > failing? I couldn't make it work. Thanks.
>
> Pls clarify.
>
> > > 2) BTW, which value should I use as a socket session ID? Currently i
> use
> > > > sessionIO.hashcode. Any better idea?
> > >
> > > System.identityHashCode() might be better for you in this case.
> >
> >
> > ***http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4990451  I don't
> quite
> > understand this.But the session ID is the most common requirement for
> every
> > socket server. Normally how people deal with this?
>
> You can create your own session id if u want. I'm doing that.
>
> > > 3) If I send the 10000 message to one of the session at the same time,
> > > would
> > > > that block the message deliever to the other sessions?
> > >
> > > If your network is fast enough, it might.  But it won't in most cases.
> >
> >
> > ***I may not explain my question clearly. My question is: my server
> keeps
> > sending the real data to end users(1000 let's say). However, some of the
> end
> > user may query something at the same time which causes my server will
> send
> > back over 10000 messages once to the session who queried. I wonder if
> the
> > size of message is too big and that the real data is queued and can't be
> > sent at the same time?
>
> This would depend on factors that you haven't told us about.
> What is the network bandwidth?
> What is the size of the messages?
> What is the hardware configuration? CPU utilization when something
> like this happens?
>
> The design of your application will determine whether something like
> what you need is possible or not.
>
> To determine whether the application is getting stuck due to network
> latency or I/O issues, check the time that the CPU is spending in I/O
> wait mode.  If it is a significant amount, then the problem is that
> your network is too slow to transport the data being generated by the
> server.
>
> HTH,
> Vinod.
>

Re: How to detect the client disconnection

Posted by Vinod Panicker <vi...@gmail.com>.
On 2/21/07, mat <fo...@gmail.com> wrote:
> Thanks. Please see *** for reply
>
> 2007/2/20, Trustin Lee <tr...@gmail.com>:
> >
> > 2007-02-20 (화), 02:13 +0800, haiyun wang 쓰시길:
> > > Hi all,
> > >
> > > I currently use mina as the Gateway and something works fine. However, I
> > > found out a problem.
> > > 1) When the client unpluged the cable, how the server knows? I think
> > server
> > > can't detect it. But how to find out the send message fail on certain
> > > sesssion.
> >
> > The bottom line is that server doesn't know and you get to know that
> > when you write something.  Please refer to this thread:
> >
> > http://tinyurl.com/2wzznb
>
>
> *** Can you kindly point out how to detect write something on session
> failing? I couldn't make it work. Thanks.

Pls clarify.

> > 2) BTW, which value should I use as a socket session ID? Currently i use
> > > sessionIO.hashcode. Any better idea?
> >
> > System.identityHashCode() might be better for you in this case.
>
>
> ***http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4990451  I don't quite
> understand this.But the session ID is the most common requirement for every
> socket server. Normally how people deal with this?

You can create your own session id if u want. I'm doing that.

> > 3) If I send the 10000 message to one of the session at the same time,
> > would
> > > that block the message deliever to the other sessions?
> >
> > If your network is fast enough, it might.  But it won't in most cases.
>
>
> ***I may not explain my question clearly. My question is: my server keeps
> sending the real data to end users(1000 let's say). However, some of the end
> user may query something at the same time which causes my server will send
> back over 10000 messages once to the session who queried. I wonder if the
> size of message is too big and that the real data is queued and can't be
> sent at the same time?

This would depend on factors that you haven't told us about.
What is the network bandwidth?
What is the size of the messages?
What is the hardware configuration? CPU utilization when something
like this happens?

The design of your application will determine whether something like
what you need is possible or not.

To determine whether the application is getting stuck due to network
latency or I/O issues, check the time that the CPU is spending in I/O
wait mode.  If it is a significant amount, then the problem is that
your network is too slow to transport the data being generated by the
server.

HTH,
Vinod.

Re: How to detect the client disconnection

Posted by mat <fo...@gmail.com>.
Thanks. Please see *** for reply

2007/2/20, Trustin Lee <tr...@gmail.com>:
>
> 2007-02-20 (화), 02:13 +0800, haiyun wang 쓰시길:
> > Hi all,
> >
> > I currently use mina as the Gateway and something works fine. However, I
> > found out a problem.
> > 1) When the client unpluged the cable, how the server knows? I think
> server
> > can't detect it. But how to find out the send message fail on certain
> > sesssion.
>
> The bottom line is that server doesn't know and you get to know that
> when you write something.  Please refer to this thread:
>
> http://tinyurl.com/2wzznb


*** Can you kindly point out how to detect write something on session
failing? I couldn't make it work. Thanks.


> 2) BTW, which value should I use as a socket session ID? Currently i use
> > sessionIO.hashcode. Any better idea?
>
> System.identityHashCode() might be better for you in this case.


***http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4990451  I don't quite
understand this.But the session ID is the most common requirement for every
socket server. Normally how people deal with this?

> 3) If I send the 10000 message to one of the session at the same time,
> would
> > that block the message deliever to the other sessions?
>
> If your network is fast enough, it might.  But it won't in most cases.


***I may not explain my question clearly. My question is: my server keeps
sending the real data to end users(1000 let's say). However, some of the end
user may query something at the same time which causes my server will send
back over 10000 messages once to the session who queried. I wonder if the
size of message is too big and that the real data is queued and can't be
sent at the same time?

HTH,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
>
>

Re: How to detect the client disconnection

Posted by Trustin Lee <tr...@gmail.com>.
2007-02-20 (화), 02:13 +0800, haiyun wang 쓰시길:
> Hi all,
> 
> I currently use mina as the Gateway and something works fine. However, I
> found out a problem.
> 1) When the client unpluged the cable, how the server knows? I think server
> can't detect it. But how to find out the send message fail on certain
> sesssion.

The bottom line is that server doesn't know and you get to know that
when you write something.  Please refer to this thread:

http://tinyurl.com/2wzznb

> 2) BTW, which value should I use as a socket session ID? Currently i use
> sessionIO.hashcode. Any better idea?

System.identityHashCode() might be better for you in this case.

> 3) If I send the 10000 message to one of the session at the same time, would
> that block the message deliever to the other sessions?

If your network is fast enough, it might.  But it won't in most cases.

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6