You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by JianXing Yi <ji...@gmail.com> on 2008/09/03 10:00:37 UTC

Why UDP sessions dropped?

Hello all,

Use case:
1 NioDatagramConnector, 5000 sessions. Each session has a sate machine and
its unique context. Each session simply loop to request from a server and
start a new request after the previous response received. The SESSION_IDLE
event has been handled every 2 seconds.

MINA version: MINA-2.0.0-M3

At start, the 5000 sessions all can be successfully established, also the
request-response cycle running well. Everything seems to be fine.
After running several minutes, the server shows session number decreased to
2000+ or 1000+ and finally 0.

>From the client viewpoint, the NioDatagramConnector shows the number of its
managed sessions is alwayls 5000 but its CPU usage drops from >90% to 0%
with no actual UDP traffic.

Any idea? Thank you very much.

Regards,
-Bing

Re: Why UDP sessions dropped?

Posted by JianXing Yi <ji...@gmail.com>.
2008/9/4 JianXing Yi <ji...@gmail.com>

>
>
> 2008/9/4 Tuure Laurinolli <tu...@indagon.com>
>
>> JianXing Yi wrote:
>>
>>> 2008/9/4 Tuure Laurinolli <tu...@indagon.com>
>>>
>>>  JianXing Yi wrote:
>>>>
>>>>  Also, I print state info in SESSION_IDLE event handling every 2
>>>>> seconds,
>>>>> all
>>>>> sessions are in a same state (STATE_A). My statemachine expects a
>>>>> MESSAGE_SENT event to trigger it transit from STATE_A to STATE_B, it is
>>>>> obvious that the session receives no MESSAGE_SENT events any more.
>>>>>
>>>>>  What generates MESSAGE_SENT events? I.e. what doesn't happen (since no
>>>> events are generated)?
>>>>
>>> >
>>
>>> MESSAGE_SENT event generated by my sending out a message.
>>>
>>
>> How? Show some code.
>>
> @IoHandlerTransition(in = STATE_GETTING, on = MESSAGE_RECEIVED, next =
> STATE_RESULT_GOT)
>     public void resultGot(IoSession session, CWTPPDU pdu) {
>             if (pdu.getPDUType() == 2) {
>                 CWTPResult res = (CWTPResult) pdu;
>                 if (!pdu.getTTR()) {
>                     segData = new ByteArrayOutputStream(65536);
>                     try {
>                         segData.write(res.getPayload());
>                         seglast = (short) 0;
>                         StateControl.breakAndGotoNext("state_getting");
>                     } catch (IOException e) {
>                         e.printStackTrace();
>                     }
>                     return;
>                 }
>             }
>
>         if (pdu.getPDUType() == 6) {
>             CWTPSegmResult segResult = (CWTPSegmResult) pdu;
>             if (seglast + 1 == segResult.getPSN())
>                 seglast = segResult.getPSN();
>             if (!segResult.getTTR())
>                 StateControl.breakAndGotoNext("state_getting");
>             else {
>                 CWTPAck ack = new CWTPAck(pdu.getTID() & 0x7fff);
>                 byte[] payload = new byte[2];
>                 payload[0] = (byte) 25;
>                 payload[1] = (byte) (0x7f & segResult.getPSN());
>                 ack.setCON(true);
>                 ack.setPayload(payload);
>
> session.write(ack);---------------------------------------------------------------->MESSAGE_SENT
> generate here
>             }
>         }
>     }
>
>     @IoHandlerTransition(in = STATE_RESULT_GOT, on = MESSAGE_SENT, next =
> STATE_GETTING)
>     public void abort(IoSession session, CWTPPDU pdu) {
>         if (WapGetterContext.numWspSession.get() * 100 / 5000 < 90) {
>             try {
>                 Thread.sleep(5L);
>             } catch (InterruptedException e) {
>                 e.printStackTrace();
>             }
>         }
>
>         CWSPGet pdu2 = null;
>
> //        if (new Random().nextInt() % 2 == 0) {
>             pdu2 = new CWSPGet("
> http://10.56.135.64/wap-pete/T2000/2kb/index.wml");
> //        } else {
> //            pdu2 = new CWSPGet("
> http://10.56.135.68/wap-pete/T2000/10kb_LG/10k_2.wml");
> //        }
>         CWTPEvent wtpEvent = new CWTPEvent(pdu2.toByteArray(), (byte) 0);
>         CWTPInvoke send = new CWTPInvoke(wtpEvent.getUserData(),
>                 tid = generateNewTID(), (byte) 2);
>         session.write(send);
>     }
>
>
>>
>>  Also, have you tried with a different number of sessions? Start with one
>>>> and find out if the behabior is the same.
>>>>
>>> >
>>
>>> I've tried with a different number of sessions, for example 1000
>>> sessions,
>>> and I've not found this behavior yet.
>>>
>>
>> Hmm, interesting.
>
> Sorry for the mistake. For StateMachine case, it will always drop to 0
session. I tried to implement it based on IoHandler and have not found this
behavior for less than 3~4000 sessions yet.

Re: Why UDP sessions dropped?

Posted by JianXing Yi <ji...@gmail.com>.
2008/9/4 Tuure Laurinolli <tu...@indagon.com>

> JianXing Yi wrote:
>
>> 2008/9/4 Tuure Laurinolli <tu...@indagon.com>
>>
>>  JianXing Yi wrote:
>>>
>>>  Also, I print state info in SESSION_IDLE event handling every 2 seconds,
>>>> all
>>>> sessions are in a same state (STATE_A). My statemachine expects a
>>>> MESSAGE_SENT event to trigger it transit from STATE_A to STATE_B, it is
>>>> obvious that the session receives no MESSAGE_SENT events any more.
>>>>
>>>>  What generates MESSAGE_SENT events? I.e. what doesn't happen (since no
>>> events are generated)?
>>>
>> >
>
>> MESSAGE_SENT event generated by my sending out a message.
>>
>
> How? Show some code.
>
@IoHandlerTransition(in = STATE_GETTING, on = MESSAGE_RECEIVED, next =
STATE_RESULT_GOT)
    public void resultGot(IoSession session, CWTPPDU pdu) {
            if (pdu.getPDUType() == 2) {
                CWTPResult res = (CWTPResult) pdu;
                if (!pdu.getTTR()) {
                    segData = new ByteArrayOutputStream(65536);
                    try {
                        segData.write(res.getPayload());
                        seglast = (short) 0;
                        StateControl.breakAndGotoNext("state_getting");
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    return;
                }
            }

        if (pdu.getPDUType() == 6) {
            CWTPSegmResult segResult = (CWTPSegmResult) pdu;
            if (seglast + 1 == segResult.getPSN())
                seglast = segResult.getPSN();
            if (!segResult.getTTR())
                StateControl.breakAndGotoNext("state_getting");
            else {
                CWTPAck ack = new CWTPAck(pdu.getTID() & 0x7fff);
                byte[] payload = new byte[2];
                payload[0] = (byte) 25;
                payload[1] = (byte) (0x7f & segResult.getPSN());
                ack.setCON(true);
                ack.setPayload(payload);

session.write(ack);---------------------------------------------------------------->MESSAGE_SENT
generate here
            }
        }
    }

    @IoHandlerTransition(in = STATE_RESULT_GOT, on = MESSAGE_SENT, next =
STATE_GETTING)
    public void abort(IoSession session, CWTPPDU pdu) {
        if (WapGetterContext.numWspSession.get() * 100 / 5000 < 90) {
            try {
                Thread.sleep(5L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        CWSPGet pdu2 = null;

//        if (new Random().nextInt() % 2 == 0) {
            pdu2 = new CWSPGet("
http://10.56.135.64/wap-pete/T2000/2kb/index.wml");
//        } else {
//            pdu2 = new CWSPGet("
http://10.56.135.68/wap-pete/T2000/10kb_LG/10k_2.wml");
//        }
        CWTPEvent wtpEvent = new CWTPEvent(pdu2.toByteArray(), (byte) 0);
        CWTPInvoke send = new CWTPInvoke(wtpEvent.getUserData(),
                tid = generateNewTID(), (byte) 2);
        session.write(send);
    }


>
>  Also, have you tried with a different number of sessions? Start with one
>>> and find out if the behabior is the same.
>>>
>> >
>
>> I've tried with a different number of sessions, for example 1000 sessions,
>> and I've not found this behavior yet.
>>
>
> Hmm, interesting.
>

Re: Why UDP sessions dropped?

Posted by Tuure Laurinolli <tu...@indagon.com>.
JianXing Yi wrote:
> 2008/9/4 Tuure Laurinolli <tu...@indagon.com>
> 
>> JianXing Yi wrote:
>>
>>> Also, I print state info in SESSION_IDLE event handling every 2 seconds,
>>> all
>>> sessions are in a same state (STATE_A). My statemachine expects a
>>> MESSAGE_SENT event to trigger it transit from STATE_A to STATE_B, it is
>>> obvious that the session receives no MESSAGE_SENT events any more.
>>>
>> What generates MESSAGE_SENT events? I.e. what doesn't happen (since no
>> events are generated)?
 >
> MESSAGE_SENT event generated by my sending out a message.

How? Show some code.

>> Also, have you tried with a different number of sessions? Start with one
>> and find out if the behabior is the same.
 >
> I've tried with a different number of sessions, for example 1000 sessions,
> and I've not found this behavior yet.

Hmm, interesting.

Re: Why UDP sessions dropped?

Posted by JianXing Yi <ji...@gmail.com>.
2008/9/4 Tuure Laurinolli <tu...@indagon.com>

> JianXing Yi wrote:
>
>> Also, I print state info in SESSION_IDLE event handling every 2 seconds,
>> all
>> sessions are in a same state (STATE_A). My statemachine expects a
>> MESSAGE_SENT event to trigger it transit from STATE_A to STATE_B, it is
>> obvious that the session receives no MESSAGE_SENT events any more.
>>
>
> What generates MESSAGE_SENT events? I.e. what doesn't happen (since no
> events are generated)?
> MESSAGE_SENT event generated by my sending out a message.
> Also, have you tried with a different number of sessions? Start with one
> and find out if the behabior is the same.
> I've tried with a different number of sessions, for example 1000 sessions,
> and I've not found this behavior yet.
>

Re: Why UDP sessions dropped?

Posted by Tuure Laurinolli <tu...@indagon.com>.
JianXing Yi wrote:
> Also, I print state info in SESSION_IDLE event handling every 2 seconds, all
> sessions are in a same state (STATE_A). My statemachine expects a
> MESSAGE_SENT event to trigger it transit from STATE_A to STATE_B, it is
> obvious that the session receives no MESSAGE_SENT events any more.

What generates MESSAGE_SENT events? I.e. what doesn't happen (since no 
events are generated)?

Also, have you tried with a different number of sessions? Start with one 
and find out if the behabior is the same.


Re: Why UDP sessions dropped?

Posted by JianXing Yi <ji...@gmail.com>.
Thank you Simon.

There is no dead locks reported by jstack.
Also, I print state info in SESSION_IDLE event handling every 2 seconds, all
sessions are in a same state (STATE_A). My statemachine expects a
MESSAGE_SENT event to trigger it transit from STATE_A to STATE_B, it is
obvious that the session receives no MESSAGE_SENT events any more.

It also seems to have no memory leak issue. The process uses about 70M
memory. After performed manually GC, it decreased to about 50M, still no
client-side session released for the NioDatagramConnector still reports 5000
sessions.

Any help is appreciated.

Regards,
-Bing

2008/9/4 Simon Trudeau <st...@bluetreewireless.com>

> Interresting, I am currently investigating a similar issue. Have you
> tried detecting deadlocks using Jstack? There is currently an open issue
> with Mina statemachine and deadlocks. Although it only occurs when you
> have 2 statemachines acting as I/O filters.
>
> http://java.sun.com/developer/technicalArticles/J2SE/monitoring/
>
> On my end I think I have a memory leak which causes your behavior but so
> far it turns out to be hard to reproduce and diagnose (my code or
> mina...)
>
> Good luck,
>
>
> Simon
> -----Original Message-----
> From: JianXing Yi [mailto:jianxing.yi@gmail.com]
> Sent: September-03-08 4:01 AM
> To: users@mina.apache.org
> Subject: Why UDP sessions dropped?
>
> Hello all,
>
> Use case:
> 1 NioDatagramConnector, 5000 sessions. Each session has a sate machine
> and its unique context. Each session simply loop to request from a
> server and start a new request after the previous response received. The
> SESSION_IDLE event has been handled every 2 seconds.
>
> MINA version: MINA-2.0.0-M3
>
> At start, the 5000 sessions all can be successfully established, also
> the request-response cycle running well. Everything seems to be fine.
> After running several minutes, the server shows session number decreased
> to
> 2000+ or 1000+ and finally 0.
>
> From the client viewpoint, the NioDatagramConnector shows the number of
> its managed sessions is alwayls 5000 but its CPU usage drops from >90%
> to 0% with no actual UDP traffic.
>
> Any idea? Thank you very much.
>
> Regards,
> -Bing
>

RE: Why UDP sessions dropped?

Posted by Simon Trudeau <st...@bluetreewireless.com>.
Interresting, I am currently investigating a similar issue. Have you
tried detecting deadlocks using Jstack? There is currently an open issue
with Mina statemachine and deadlocks. Although it only occurs when you
have 2 statemachines acting as I/O filters.

http://java.sun.com/developer/technicalArticles/J2SE/monitoring/

On my end I think I have a memory leak which causes your behavior but so
far it turns out to be hard to reproduce and diagnose (my code or
mina...)

Good luck,


Simon 
-----Original Message-----
From: JianXing Yi [mailto:jianxing.yi@gmail.com] 
Sent: September-03-08 4:01 AM
To: users@mina.apache.org
Subject: Why UDP sessions dropped?

Hello all,

Use case:
1 NioDatagramConnector, 5000 sessions. Each session has a sate machine
and its unique context. Each session simply loop to request from a
server and start a new request after the previous response received. The
SESSION_IDLE event has been handled every 2 seconds.

MINA version: MINA-2.0.0-M3

At start, the 5000 sessions all can be successfully established, also
the request-response cycle running well. Everything seems to be fine.
After running several minutes, the server shows session number decreased
to
2000+ or 1000+ and finally 0.

>From the client viewpoint, the NioDatagramConnector shows the number of
its managed sessions is alwayls 5000 but its CPU usage drops from >90%
to 0% with no actual UDP traffic.

Any idea? Thank you very much.

Regards,
-Bing