You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by AmalRaj P <am...@dhyanit.com> on 2007/12/11 15:11:56 UTC

Packet loss Issue

In my project I am using MINA framework for notification, with multiple
clients in place I faced packet loss issues. 

Then I planned to setup a sample environment with a server and three clients
connected to it. 

Server:

Will publish numbers generated in loop to all clients connected/registered

public void run()
    {
        IoSession session = null;
        int j = 0;
        while (j < 500)
        {
            for (int i = 0; i < sessions.size(); i++)
            {
                String msg = "For client " + i + " value sent is:" + j;
                System.out.println(msg);
                byte data[] = NotificationObject.getBytes(new String(msg));
                ByteBuffer buffer = ByteBuffer.wrap(data);
                session = (IoSession) sessions.get(i);
                session.write(buffer);
                buffer.release();
                buffer = null;

            }
            j++;
        }
    }


Client:

Will just receive the message and print it

  public void messageReceived(IoSession session, Object message)
    {
        ByteBuffer buffer = (ByteBuffer) message;
        byte[] data = new byte[buffer.remaining()];
        buffer.get(data);
        Object obj = NotificationObject.getObject(data);
        System.out.println("ClientHandler : data received is : " + obj);
    }


Results:

Client1  			Missed: 203, 253, 293

Client2  			Missed: 204, 252

Client3  			Missed: 247, 252

I don’t know why I am getting packet loss in the Client side. Need some help
as every single notification in our process cannot be missed.

I have attached the test setup. Just use the batch files inside bin. Sample
logs where you can see the issues are also available.
http://www.nabble.com/file/p14274506/MinaTestSetup.zip MinaTestSetup.zip 
-- 
View this message in context: http://www.nabble.com/Packet-loss-Issue-tp14274506s16868p14274506.html
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: Packet loss Issue

Posted by AmalRaj P <am...@dhyanit.com>.
Oops forgot to communicate. Codec's solved my problem. Thanks for that. 
-- 
View this message in context: http://www.nabble.com/Packet-loss-Issue-tp14274506s16868p14630530.html
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: Packet loss Issue

Posted by Niklas Therning <ni...@trillian.se>.
AmalRaj P wrote:
> Client:
>
> Will just receive the message and print it
>
>   public void messageReceived(IoSession session, Object message)
>     {
>         ByteBuffer buffer = (ByteBuffer) message;
>         byte[] data = new byte[buffer.remaining()];
>         buffer.get(data);
>         Object obj = NotificationObject.getObject(data);
>         System.out.println("ClientHandler : data received is : " + obj);
>     }
>
>
> Results:
>
> Client1  			Missed: 203, 253, 293
>
> Client2  			Missed: 204, 252
>
> Client3  			Missed: 247, 252
>
> I don’t know why I am getting packet loss in the Client side. Need some help
> as every single notification in our process cannot be missed.
>   

You cannot expect one write() on the server side to correspond to one 
messageReceived() call on the client side. The network layer may decide 
to split/combine bytes in order to optimize transport as it sees fit. 
Please have a look at the ProtocolCodecFilter. There's a nice tutorial 
which explains how to use it on the MINA web site. If you are using the 
latest trunk version of MINA I think there is a new codec implmentation 
in there which sends length prefixed string. It seems like you could use 
that out of the box.

HTH

/Niklas

Re: Packet loss Issue

Posted by AmalRaj P <am...@dhyanit.com>.
I removed the following lines in the NotificationThread.java as suggested by
the you in the test setup and tried the same (3 clients + 1 server + 500
notifications) what we done before. We are not getting the notifications
drop every time. But if you try the same 3 or 4 times, then you will get the
notification drops in the client.

Removed lines from the NotificationThread.java
---------------------------------------------------------
buffer.release();
buffer = null;

FYI: the behavior differs in Windows & Linux. In Linux I am getting the
notification drops very often compare than windows. 

Kindly help me to resolve the issue. Thanks.



Trustin Lee wrote:
> 
> It's unlikely that MINA misses any data unless there's disconnection.
> 
> It might be because you are releasing the buffer unnecessarily.
> Please remove the two lines (buffer.release() and buffer = null).
> Also, make sure no exception is caught in your IoHandler
> implementation.
> 
> There's also possibility you are not taking care of TCP/IP packet
> fragmentation in NotificationObject.getObject(...) (i.e. two messages
> are received in one ByteBuffer.)
> 
> Trustin
> 
> On Dec 11, 2007 11:11 PM, AmalRaj P <am...@dhyanit.com> wrote:
>>
>> In my project I am using MINA framework for notification, with multiple
>> clients in place I faced packet loss issues.
>>
>> Then I planned to setup a sample environment with a server and three
>> clients
>> connected to it.
>>
>> Server:
>>
>> Will publish numbers generated in loop to all clients
>> connected/registered
>>
>> public void run()
>>     {
>>         IoSession session = null;
>>         int j = 0;
>>         while (j < 500)
>>         {
>>             for (int i = 0; i < sessions.size(); i++)
>>             {
>>                 String msg = "For client " + i + " value sent is:" + j;
>>                 System.out.println(msg);
>>                 byte data[] = NotificationObject.getBytes(new
>> String(msg));
>>                 ByteBuffer buffer = ByteBuffer.wrap(data);
>>                 session = (IoSession) sessions.get(i);
>>                 session.write(buffer);
>>                 buffer.release();
>>                 buffer = null;
>>
>>             }
>>             j++;
>>         }
>>     }
>>
>>
>> Client:
>>
>> Will just receive the message and print it
>>
>>   public void messageReceived(IoSession session, Object message)
>>     {
>>         ByteBuffer buffer = (ByteBuffer) message;
>>         byte[] data = new byte[buffer.remaining()];
>>         buffer.get(data);
>>         Object obj = NotificationObject.getObject(data);
>>         System.out.println("ClientHandler : data received is : " + obj);
>>     }
>>
>>
>> Results:
>>
>> Client1                         Missed: 203, 253, 293
>>
>> Client2                         Missed: 204, 252
>>
>> Client3                         Missed: 247, 252
>>
>> I don't know why I am getting packet loss in the Client side. Need some
>> help
>> as every single notification in our process cannot be missed.
>>
>> I have attached the test setup. Just use the batch files inside bin.
>> Sample
>> logs where you can see the issues are also available.
>> http://www.nabble.com/file/p14274506/MinaTestSetup.zip MinaTestSetup.zip
>> --
>> View this message in context:
>> http://www.nabble.com/Packet-loss-Issue-tp14274506s16868p14274506.html
>> Sent from the Apache MINA Support Forum mailing list archive at
>> Nabble.com.
>>
>>
> 
> 
> 
> -- 
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
> 
> 

-- 
View this message in context: http://www.nabble.com/Packet-loss-Issue-tp14274506s16868p14295021.html
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: Packet loss Issue

Posted by Trustin Lee <tr...@gmail.com>.
It's unlikely that MINA misses any data unless there's disconnection.

It might be because you are releasing the buffer unnecessarily.
Please remove the two lines (buffer.release() and buffer = null).
Also, make sure no exception is caught in your IoHandler
implementation.

There's also possibility you are not taking care of TCP/IP packet
fragmentation in NotificationObject.getObject(...) (i.e. two messages
are received in one ByteBuffer.)

Trustin

On Dec 11, 2007 11:11 PM, AmalRaj P <am...@dhyanit.com> wrote:
>
> In my project I am using MINA framework for notification, with multiple
> clients in place I faced packet loss issues.
>
> Then I planned to setup a sample environment with a server and three clients
> connected to it.
>
> Server:
>
> Will publish numbers generated in loop to all clients connected/registered
>
> public void run()
>     {
>         IoSession session = null;
>         int j = 0;
>         while (j < 500)
>         {
>             for (int i = 0; i < sessions.size(); i++)
>             {
>                 String msg = "For client " + i + " value sent is:" + j;
>                 System.out.println(msg);
>                 byte data[] = NotificationObject.getBytes(new String(msg));
>                 ByteBuffer buffer = ByteBuffer.wrap(data);
>                 session = (IoSession) sessions.get(i);
>                 session.write(buffer);
>                 buffer.release();
>                 buffer = null;
>
>             }
>             j++;
>         }
>     }
>
>
> Client:
>
> Will just receive the message and print it
>
>   public void messageReceived(IoSession session, Object message)
>     {
>         ByteBuffer buffer = (ByteBuffer) message;
>         byte[] data = new byte[buffer.remaining()];
>         buffer.get(data);
>         Object obj = NotificationObject.getObject(data);
>         System.out.println("ClientHandler : data received is : " + obj);
>     }
>
>
> Results:
>
> Client1                         Missed: 203, 253, 293
>
> Client2                         Missed: 204, 252
>
> Client3                         Missed: 247, 252
>
> I don't know why I am getting packet loss in the Client side. Need some help
> as every single notification in our process cannot be missed.
>
> I have attached the test setup. Just use the batch files inside bin. Sample
> logs where you can see the issues are also available.
> http://www.nabble.com/file/p14274506/MinaTestSetup.zip MinaTestSetup.zip
> --
> View this message in context: http://www.nabble.com/Packet-loss-Issue-tp14274506s16868p14274506.html
> Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.
>
>



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