You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Steve Johns <st...@gmail.com> on 2007/12/13 16:35:20 UTC

Newbie Questions

Thanks for Mina. It is a great project.
After I am trying out the Mina, I had some questions.
1) If the server session.write() a message, however client network is really
SLOW. Will mina keep trying to send
out the message until timeout?(I guess session.settimeout() is applied
here). If so, how IoHandler get notified from this
event message? (Through exceptionCaught, close session?). Why NOT
accumulated writeQueue size > user defined size and exception?
2) If the server wants to send the same message to all 1000 sessions, should
I encode the same message 1000 times
in the encoder extend the messageEncoder? If so, that kinda affects the
performance.
3) In Mina web document, source code 1.1.x->main
the "WORK" class link under org.apache.mina.transport.socket.nio is wrong.

Finally, thanks Trustin.

Re: Newbie Questions

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

On Dec 21, 2007 6:36 PM, Steve Johns <st...@gmail.com> wrote:
> On Dec 17, 2007 12:17 PM, Trustin Lee <tr...@gmail.com> wrote:
> > On Dec 15, 2007 11:55 AM, Steve Johns <st...@gmail.com> wrote:
> > > I may not make myself clear. If I send 100 bytes length of packets,
> > however,
> > > only 50 bytes are sent. (int sentBytes = socket.write(bytes[])).  I
> > meant if
> > > Mina will put the left 50 bytes back to the queue and send them again?
> >
> > Yes.  MINA will try to send when the NIO selector tells MINA that the
> > kernel buffer is reday to receive more write requests.
>
> So Mina will keep re-sending the packets which sent failure last time? I
> meant re-send the left 50bytes[] in my example?

It's not actually failure but only the buffer-full situation.  MINA
tried to write again the lest 50 bytes[] in your example later when
the buffer is not full anymore.

Therefore, in MINA TCP transport, however big buffer you send, it will
be sent finally as long as the connection is open.  Of course, your
data will be truncated if you are using the UDP transport.

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

Re: Newbie Questions

Posted by Steve Johns <st...@gmail.com>.
On Dec 17, 2007 12:17 PM, Trustin Lee <tr...@gmail.com> wrote:

> On Dec 15, 2007 11:55 AM, Steve Johns <st...@gmail.com> wrote:
> > On Dec 15, 2007 5:52 AM, Mike Heath <mh...@apache.org> wrote:
> >
> > > Steve Johns wrote:
> > > > Thanks for Mina. It is a great project.
> > > > After I am trying out the Mina, I had some questions.
> > > > 1) If the server session.write() a message, however client network
> is
> > > really
> > > > SLOW. Will mina keep trying to send
> > > > out the message until timeout?(I guess session.settimeout() is
> applied
> > > > here). If so, how IoHandler get notified from this
> > > > event message? (Through exceptionCaught, close session?). Why NOT
> > > > accumulated writeQueue size > user defined size and exception?
> > >
> > > MINA only passes the message on to the OS once.  It is the OS'
> > > responsibility to manage TCP timeouts and resend dropped packets.  If
> > > the TCP connection timesout, an exception will be thrown and it can be
> > > handled in IoHandler.exceptionCaught.
> >
> > I may not make myself clear. If I send 100 bytes length of packets,
> however,
> > only 50 bytes are sent. (int sentBytes = socket.write(bytes[])).  I
> meant if
> > Mina will put the left 50 bytes back to the queue and send them again?
>
> Yes.  MINA will try to send when the NIO selector tells MINA that the
> kernel buffer is reday to receive more write requests.

So Mina will keep re-sending the packets which sent failure last time? I
meant re-send the left 50bytes[] in my example?

>
>
> > > > 2) If the server wants to send the same message to all 1000
> sessions,
> > > should
> > > > I encode the same message 1000 times
> > > > in the encoder extend the messageEncoder? If so, that kinda affects
> the
> > > > performance.
> > >
> > > If you send the message as a Java Object, it will have to be encoded
> > > 1,000 times.  If you're going to be broadcasting a message to lots of
> > > clients, I would recommend encoding it once, and then doing something
> > > like:
> > >
> > > for (IoSession session : allRecipients) {
> > >  session.write(myEncodedBuffer.duplicate());
> > > }
> >
> > Which means I have to do the Encode part in the IoHandlerAdapter but NOT
> in
> > my encoder, right?  That really mixes up the communication and business
> > logic.
>
> Well, it doesn't necessarily mean that.  You can use some cache in
> your encoder to avoid encoding the same message over and over, not
> hurting the separation of concerns.
>
> > > > Finally, thanks Trustin.
> > >
> > > Yes, Trustin is my hero.
> >
> > You are my hero, too. :)
>
> Any costume for me?  :D
>
> HTH,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
>

Re: Newbie Questions

Posted by Trustin Lee <tr...@gmail.com>.
On Dec 15, 2007 11:55 AM, Steve Johns <st...@gmail.com> wrote:
> On Dec 15, 2007 5:52 AM, Mike Heath <mh...@apache.org> wrote:
>
> > Steve Johns wrote:
> > > Thanks for Mina. It is a great project.
> > > After I am trying out the Mina, I had some questions.
> > > 1) If the server session.write() a message, however client network is
> > really
> > > SLOW. Will mina keep trying to send
> > > out the message until timeout?(I guess session.settimeout() is applied
> > > here). If so, how IoHandler get notified from this
> > > event message? (Through exceptionCaught, close session?). Why NOT
> > > accumulated writeQueue size > user defined size and exception?
> >
> > MINA only passes the message on to the OS once.  It is the OS'
> > responsibility to manage TCP timeouts and resend dropped packets.  If
> > the TCP connection timesout, an exception will be thrown and it can be
> > handled in IoHandler.exceptionCaught.
>
> I may not make myself clear. If I send 100 bytes length of packets, however,
> only 50 bytes are sent. (int sentBytes = socket.write(bytes[])).  I meant if
> Mina will put the left 50 bytes back to the queue and send them again?

Yes.  MINA will try to send when the NIO selector tells MINA that the
kernel buffer is reday to receive more write requests.

> > > 2) If the server wants to send the same message to all 1000 sessions,
> > should
> > > I encode the same message 1000 times
> > > in the encoder extend the messageEncoder? If so, that kinda affects the
> > > performance.
> >
> > If you send the message as a Java Object, it will have to be encoded
> > 1,000 times.  If you're going to be broadcasting a message to lots of
> > clients, I would recommend encoding it once, and then doing something
> > like:
> >
> > for (IoSession session : allRecipients) {
> >  session.write(myEncodedBuffer.duplicate());
> > }
>
> Which means I have to do the Encode part in the IoHandlerAdapter but NOT in
> my encoder, right?  That really mixes up the communication and business
> logic.

Well, it doesn't necessarily mean that.  You can use some cache in
your encoder to avoid encoding the same message over and over, not
hurting the separation of concerns.

> > > Finally, thanks Trustin.
> >
> > Yes, Trustin is my hero.
>
> You are my hero, too. :)

Any costume for me?  :D

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

Re: Newbie Questions

Posted by Steve Johns <st...@gmail.com>.
On Dec 15, 2007 5:52 AM, Mike Heath <mh...@apache.org> wrote:

> Steve Johns wrote:
> > Thanks for Mina. It is a great project.
> > After I am trying out the Mina, I had some questions.
> > 1) If the server session.write() a message, however client network is
> really
> > SLOW. Will mina keep trying to send
> > out the message until timeout?(I guess session.settimeout() is applied
> > here). If so, how IoHandler get notified from this
> > event message? (Through exceptionCaught, close session?). Why NOT
> > accumulated writeQueue size > user defined size and exception?
>
> MINA only passes the message on to the OS once.  It is the OS'
> responsibility to manage TCP timeouts and resend dropped packets.  If
> the TCP connection timesout, an exception will be thrown and it can be
> handled in IoHandler.exceptionCaught.

I may not make myself clear. If I send 100 bytes length of packets, however,
only 50 bytes are sent. (int sentBytes = socket.write(bytes[])).  I meant if
Mina will put the left 50 bytes back to the queue and send them again?

>
>
> > 2) If the server wants to send the same message to all 1000 sessions,
> should
> > I encode the same message 1000 times
> > in the encoder extend the messageEncoder? If so, that kinda affects the
> > performance.
>
> If you send the message as a Java Object, it will have to be encoded
> 1,000 times.  If you're going to be broadcasting a message to lots of
> clients, I would recommend encoding it once, and then doing something
> like:
>
> for (IoSession session : allRecipients) {
>  session.write(myEncodedBuffer.duplicate());
> }

Which means I have to do the Encode part in the IoHandlerAdapter but NOT in
my encoder, right?  That really mixes up the communication and business
logic.

>
>
> or if you're using MINA TRUNK, you could just use IoUtil.broadcast.

Sounded great.

>
>
> > 3) In Mina web document, source code 1.1.x->main
> > the "WORK" class link under org.apache.mina.transport.socket.nio is
> wrong.
>
> I'm sorry.  I don't understand where this link problem is.  Please
> clarify on this.
>
> > Finally, thanks Trustin.
>
> Yes, Trustin is my hero.

You are my hero, too. :)

>
>
> -Mike
>

Re: Newbie Questions

Posted by Mike Heath <mh...@apache.org>.
Steve Johns wrote:
> Thanks for Mina. It is a great project.
> After I am trying out the Mina, I had some questions.
> 1) If the server session.write() a message, however client network is really
> SLOW. Will mina keep trying to send
> out the message until timeout?(I guess session.settimeout() is applied
> here). If so, how IoHandler get notified from this
> event message? (Through exceptionCaught, close session?). Why NOT
> accumulated writeQueue size > user defined size and exception?

MINA only passes the message on to the OS once.  It is the OS'
responsibility to manage TCP timeouts and resend dropped packets.  If
the TCP connection timesout, an exception will be thrown and it can be
handled in IoHandler.exceptionCaught.

> 2) If the server wants to send the same message to all 1000 sessions, should
> I encode the same message 1000 times
> in the encoder extend the messageEncoder? If so, that kinda affects the
> performance.

If you send the message as a Java Object, it will have to be encoded
1,000 times.  If you're going to be broadcasting a message to lots of
clients, I would recommend encoding it once, and then doing something like:

for (IoSession session : allRecipients) {
  session.write(myEncodedBuffer.duplicate());
}

or if you're using MINA TRUNK, you could just use IoUtil.broadcast.

> 3) In Mina web document, source code 1.1.x->main
> the "WORK" class link under org.apache.mina.transport.socket.nio is wrong.

I'm sorry.  I don't understand where this link problem is.  Please
clarify on this.

> Finally, thanks Trustin.

Yes, Trustin is my hero.

-Mike