You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Lee Kemp <le...@anywebcam.com> on 2006/09/07 09:58:57 UTC

Message containing start of next message

Hi All,

I am having a small (hopefully) problem.

I have just deployed a new app that I have written using mina to our  
production servers and when doing some load testing noticed that some  
of the message objects contain the header that should be on the next  
message. We don't have this problem on our development server when  
testing it on our local network so it must be something happening to  
the packets on the way to the server.

Has anyone else experienced this issue?

At the moment the only fix I can think of is writing a new filter to  
buffer all the messages before I pass them off the protocol handler.

Any help would be greatly appreciated!

Lee. 

Re: Message containing start of next message

Posted by Trustin Lee <tr...@gmail.com>.
On 9/8/06, wolverine my <wo...@gmail.com> wrote:
>
> Hi!
>
> If I understood correctly we should always use
> DemuxingProtocolCodecFactory since most of the socket connections are
> TCP/IP, this include HTTP server, Chat server and etc. May I know in
> what scenario that we will choose other codec over the
> DemuxingProtocolCodecFactory? I think it would be very helpful if we
> can add some guidelines into the API description.


In case of text protocol, you could use TextLineProtocolCodecFactory.  Most
binary protocols will be fine with DemuxingProtocolCodecFactory, but if your
protocol doesn't fit to your needs, then you can use
CumulativeProtocolDecoder.  Actually DemuxingProtocolCodecFactory is using
CumulativeProtocolDecoder internally.

Trustin
-- 
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: Message containing start of next message

Posted by wolverine my <wo...@gmail.com>.
Hi!

If I understood correctly we should always use
DemuxingProtocolCodecFactory since most of the socket connections are
TCP/IP, this include HTTP server, Chat server and etc. May I know in
what scenario that we will choose other codec over the
DemuxingProtocolCodecFactory? I think it would be very helpful if we
can add some guidelines into the API description.


On 9/8/06, Trustin Lee <tr...@gmail.com> wrote:
> Hi Lee,
>
> On 9/8/06, Lee Kemp <le...@anywebcam.com> wrote:
> >
> > Thanks Trustin,
> >
> > Just to answer Nilas I am using Mina 0.9.5 on Fedora Core 4.
> >
> > I have changed my codec to use DemuxingProtocolCodecFactory and it
> > has made a big difference.  I am not longer receiving messages
> > missing there headers but I am still getting some (not as many) with
> > the header of the next message on the end of it.
> >
> > if the length of the message is to long I am returning
> > MessageDecoder.NOT_OK in my decodable method. If I do this a then a
> > "ProtocolDecoderException: No appropriate message decoder" gets
> > thrown by the DemuxingProtocolCodecFactory and the user gets
> > disconnected from the server.
> >
> > Is there a better way for me to check if my message is to long or to
> > make sure it stops at the next messages header?
>
>
> You shouldn't return NOT_OK but return OK after reading until just before
> the beginning of the next message.  Then DemuxingProtocolCodecFilter will
> take care of splitting the next message for you.  And there can be a case
> when the received buffer doesn't contain a whole message, then you have to
> return NOT_YET, then DemuxingProtocolCodecFilter will call the decoder again
> when more data is received.
>
> BTW I think you really need to understand how TCP/IP works because it's not
> a problem of MINA, but it's an expected behavior of TCP/IP.
>
> Trustin
> --
> 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: Message containing start of next message

Posted by Trustin Lee <tr...@gmail.com>.
Hi Lee,

On 9/8/06, Lee Kemp <le...@anywebcam.com> wrote:
>
> Thanks Trustin,
>
> Just to answer Nilas I am using Mina 0.9.5 on Fedora Core 4.
>
> I have changed my codec to use DemuxingProtocolCodecFactory and it
> has made a big difference.  I am not longer receiving messages
> missing there headers but I am still getting some (not as many) with
> the header of the next message on the end of it.
>
> if the length of the message is to long I am returning
> MessageDecoder.NOT_OK in my decodable method. If I do this a then a
> "ProtocolDecoderException: No appropriate message decoder" gets
> thrown by the DemuxingProtocolCodecFactory and the user gets
> disconnected from the server.
>
> Is there a better way for me to check if my message is to long or to
> make sure it stops at the next messages header?


You shouldn't return NOT_OK but return OK after reading until just before
the beginning of the next message.  Then DemuxingProtocolCodecFilter will
take care of splitting the next message for you.  And there can be a case
when the received buffer doesn't contain a whole message, then you have to
return NOT_YET, then DemuxingProtocolCodecFilter will call the decoder again
when more data is received.

BTW I think you really need to understand how TCP/IP works because it's not
a problem of MINA, but it's an expected behavior of TCP/IP.

Trustin
-- 
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: Message containing start of next message

Posted by Lee Kemp <le...@anywebcam.com>.
Thanks Trustin,

Just to answer Nilas I am using Mina 0.9.5 on Fedora Core 4.

I have changed my codec to use DemuxingProtocolCodecFactory and it  
has made a big difference.  I am not longer receiving messages  
missing there headers but I am still getting some (not as many) with  
the header of the next message on the end of it.

if the length of the message is to long I am returning  
MessageDecoder.NOT_OK in my decodable method. If I do this a then a  
"ProtocolDecoderException: No appropriate message decoder" gets  
thrown by the DemuxingProtocolCodecFactory and the user gets  
disconnected from the server.

Is there a better way for me to check if my message is to long or to  
make sure it stops at the next messages header?
Also can I stop it from disconnecting the user and just ignore the  
message?

Thanks again for all your help guys!

Lee.


On 07/09/2006, at 7:53 PM, Trustin Lee wrote:

> On 9/7/06, Lee Kemp <le...@anywebcam.com> wrote:
>>
>> Hi All,
>>
>> I am having a small (hopefully) problem.
>>
>> I have just deployed a new app that I have written using mina to our
>> production servers and when doing some load testing noticed that some
>> of the message objects contain the header that should be on the next
>> message. We don't have this problem on our development server when
>> testing it on our local network so it must be something happening to
>> the packets on the way to the server.
>>
>> Has anyone else experienced this issue?
>
>
> If you are using TCP/IP, it can always happen.  It's a nature of  
> TCP/IP.
> Packets can be merged and splitted due to network or load  
> condition.  So you
> have to interpret the ByteBuffer considering this issue.   
> Fortunately, we
> already provide a solution for this issue.  Please take a look into  
> SumUp
> example and see how we implemented our codec using
> DemuxingProtocolCodecFactory.
>
> Trustin
> -- 
> 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: Message containing start of next message

Posted by Trustin Lee <tr...@gmail.com>.
On 9/7/06, Lee Kemp <le...@anywebcam.com> wrote:
>
> Hi All,
>
> I am having a small (hopefully) problem.
>
> I have just deployed a new app that I have written using mina to our
> production servers and when doing some load testing noticed that some
> of the message objects contain the header that should be on the next
> message. We don't have this problem on our development server when
> testing it on our local network so it must be something happening to
> the packets on the way to the server.
>
> Has anyone else experienced this issue?


If you are using TCP/IP, it can always happen.  It's a nature of TCP/IP.
Packets can be merged and splitted due to network or load condition.  So you
have to interpret the ByteBuffer considering this issue.  Fortunately, we
already provide a solution for this issue.  Please take a look into SumUp
example and see how we implemented our codec using
DemuxingProtocolCodecFactory.

Trustin
-- 
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: Message containing start of next message

Posted by Niklas Therning <ni...@trillian.se>.
Hi,

Please let us know which MINA version, what platform and which JRE 
you're using.

/Niklas

Lee Kemp wrote:
> Hi All,
> 
> I am having a small (hopefully) problem.
> 
> I have just deployed a new app that I have written using mina to our 
> production servers and when doing some load testing noticed that some of 
> the message objects contain the header that should be on the next 
> message. We don't have this problem on our development server when 
> testing it on our local network so it must be something happening to the 
> packets on the way to the server.
> 
> Has anyone else experienced this issue?
> 
> At the moment the only fix I can think of is writing a new filter to 
> buffer all the messages before I pass them off the protocol handler.
> 
> Any help would be greatly appreciated!
> 
> Lee.