You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Emmanuel Lécharny <el...@gmail.com> on 2013/03/22 10:53:29 UTC

[MINA 3] UDP support

Hi guys,

I'm currently working on the UDP support for MINA 3. Here is the way I
see the way to implement it, just tell me if you have any better idea,
suggestion, whatever.

First of all, there is a major difference between TCP and UDP : we don't
have to manage an OP_ACCEPT event for UDP. That means we just register
the socket on a selector for OP_READ events, and we process the incoming
data on the fly.

That has one direct consequence : we have to create the sessions based
on the remote address, and we have to assume that a request coming from
this remote address is associated with this session (in other words, if
the server does not close the session, and if we don't manage iddle
sessions, we will keep a session for a remote address forever).

So the algorithm would be somthing like :

select()
for each selectionKey selected because of an OP_READ event
  do
    find the associated session, based on the remote address
    if we get one,
      then process the data generating a messageReceived event
      else
        create a new session
        send a sessionCreated and sessionOpened event
        process the data generating a messageReceived event

This is a very rough description of how the main loop works.

Some few valuable bits :

1) We need one single thread to manage all the incoming messages. The
server will register the DatagramChannel on one single selector anyway...
2) As we use one single thread to process all the incoming messages, we
wil have to spread the load after having read the data. We will need an
executor for that (this is not mandatory, but this is the only way to
scale).
As a consequence, assuming we use a pool of thread to manage the events,
we need to guarantee that the messageReceived event is processed *after*
the sessionCreated and sessionOpened events.
3) One idea is to associate an event queue to each sessio. When we
create the session, we push three events in this queue : the
sessionCreated event, then the sessionOpened one, and finally, the
messageReceived event. Then we can peek a thread and let it process the
events.
4) Or we can associate one single thread to the session ( a bit like
what is done in MINA 2). It could make sense if we want to order the
event processing. I prefer the previous solution though.

So, wdyt ?

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


Re: [MINA 3] UDP support

Posted by Jeff MAURY <je...@jeffmaury.com>.
I think it is a little different on the client side because you need a
session to be able to store a socket address.
Maybe the API is not adequate for ADP.

Jeff


On Sat, Mar 23, 2013 at 7:29 AM, Emmanuel Lécharny <el...@gmail.com>wrote:

> Le 3/23/13 7:16 AM, Julien Vermillard a écrit :
> > Le 22 mars 2013 23:35, "Emmanuel Lécharny" <el...@gmail.com> a
> écrit :
> >> Le 3/22/13 10:51 PM, Jeff MAURY a écrit :
> >>> On Fri, Mar 22, 2013 at 10:05 PM, Emmanuel Lecharny <
> > elecharny@apache.org>wrote:
> >>>> Le 22 mars 2013 21:26, "Jeff MAURY" <je...@jeffmaury.com> a
> écrit :
> >>>>> Sorry, I missed my point.
> >>>>> My intent is not to remove the session concept from the MINA UDP API
> > but
> >>>>> rather to say that trying to implement the concept of a virtual
> > session
> >>>>> like Emmanuel proposes seems to me that this will put some kind of
> >>>> overhead
> >>>>> in the MINA processing (and maybe memory leaks as well) for a use
> case
> >>>> that
> >>>>> I don't see being relevant except for 1%
> >>>> What we call a 'session' here is just a container with a state. If the
> >>>> application does not want to do anything with it, no pb.
> >>>>
> >>> What I try to explain is that you are implementing a session for a use
> > case
> >>> that I think is very specific.
> >> Yes, but this is the way the MINA framework is designed : we have
> >> session in the IoHandler...
> >>
> >> Now, I wonder if we really need to manage Session instances when we have
> >> incoming UDP messages : wouldn't it be better to propagate a static
> >> Session instance that only contain the scoketAddress from the caller,
> >> taken from a pool of session instances ?
> >>
> >> I guess that it's what you have in mind...
> >>
> > Static session would make a lot of sense for broadcast or multicast.
> Sorry, I meant pre-allocated, not static. As we store some informations
> about the caller (remote address/port) in the session, it's not possible
> to use a static session.
>
> In any case, I think we have to propose a unmanaged UDP server (where we
> don't manage idle, nor stats), and an optionnal managed UDP server, as
> suggested by Jeff.
>
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.iktek.com
>
>


-- 
Jeff MAURY


"Legacy code" often differs from its suggested alternative by actually
working and scaling.
 - Bjarne Stroustrup

http://www.jeffmaury.com
http://riadiscuss.jeffmaury.com
http://www.twitter.com/jeffmaury

Re: [MINA 3] UDP support

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 3/23/13 7:16 AM, Julien Vermillard a écrit :
> Le 22 mars 2013 23:35, "Emmanuel Lécharny" <el...@gmail.com> a écrit :
>> Le 3/22/13 10:51 PM, Jeff MAURY a écrit :
>>> On Fri, Mar 22, 2013 at 10:05 PM, Emmanuel Lecharny <
> elecharny@apache.org>wrote:
>>>> Le 22 mars 2013 21:26, "Jeff MAURY" <je...@jeffmaury.com> a écrit :
>>>>> Sorry, I missed my point.
>>>>> My intent is not to remove the session concept from the MINA UDP API
> but
>>>>> rather to say that trying to implement the concept of a virtual
> session
>>>>> like Emmanuel proposes seems to me that this will put some kind of
>>>> overhead
>>>>> in the MINA processing (and maybe memory leaks as well) for a use case
>>>> that
>>>>> I don't see being relevant except for 1%
>>>> What we call a 'session' here is just a container with a state. If the
>>>> application does not want to do anything with it, no pb.
>>>>
>>> What I try to explain is that you are implementing a session for a use
> case
>>> that I think is very specific.
>> Yes, but this is the way the MINA framework is designed : we have
>> session in the IoHandler...
>>
>> Now, I wonder if we really need to manage Session instances when we have
>> incoming UDP messages : wouldn't it be better to propagate a static
>> Session instance that only contain the scoketAddress from the caller,
>> taken from a pool of session instances ?
>>
>> I guess that it's what you have in mind...
>>
> Static session would make a lot of sense for broadcast or multicast.
Sorry, I meant pre-allocated, not static. As we store some informations
about the caller (remote address/port) in the session, it's not possible
to use a static session.

In any case, I think we have to propose a unmanaged UDP server (where we
don't manage idle, nor stats), and an optionnal managed UDP server, as
suggested by Jeff.


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


Re: [MINA 3] UDP support

Posted by Julien Vermillard <jv...@gmail.com>.
Le 22 mars 2013 23:35, "Emmanuel Lécharny" <el...@gmail.com> a écrit :
>
> Le 3/22/13 10:51 PM, Jeff MAURY a écrit :
> > On Fri, Mar 22, 2013 at 10:05 PM, Emmanuel Lecharny <
elecharny@apache.org>wrote:
> >
> >> Le 22 mars 2013 21:26, "Jeff MAURY" <je...@jeffmaury.com> a écrit :
> >>> Sorry, I missed my point.
> >>> My intent is not to remove the session concept from the MINA UDP API
but
> >>> rather to say that trying to implement the concept of a virtual
session
> >>> like Emmanuel proposes seems to me that this will put some kind of
> >> overhead
> >>> in the MINA processing (and maybe memory leaks as well) for a use case
> >> that
> >>> I don't see being relevant except for 1%
> >> What we call a 'session' here is just a container with a state. If the
> >> application does not want to do anything with it, no pb.
> >>
> > What I try to explain is that you are implementing a session for a use
case
> > that I think is very specific.
>
> Yes, but this is the way the MINA framework is designed : we have
> session in the IoHandler...
>
> Now, I wonder if we really need to manage Session instances when we have
> incoming UDP messages : wouldn't it be better to propagate a static
> Session instance that only contain the scoketAddress from the caller,
> taken from a pool of session instances ?
>
> I guess that it's what you have in mind...
>

Static session would make a lot of sense for broadcast or multicast.

> >
> >> Although it's for Mina a way to gather stats (nv msg sent, etc) and to
> >> offer convenient methods (events). Nothing more.
> >>
> > In my opinion, you are mixing two different aspects.
> > The statistics should be available globally for UDP, ie on the port
level.
>
> Right. We can probably re-think the way it currently works.
>
> Thanks for the heads up.
>

Re: [MINA 3] UDP support

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 3/22/13 10:51 PM, Jeff MAURY a écrit :
> On Fri, Mar 22, 2013 at 10:05 PM, Emmanuel Lecharny <el...@apache.org>wrote:
>
>> Le 22 mars 2013 21:26, "Jeff MAURY" <je...@jeffmaury.com> a écrit :
>>> Sorry, I missed my point.
>>> My intent is not to remove the session concept from the MINA UDP API but
>>> rather to say that trying to implement the concept of a virtual session
>>> like Emmanuel proposes seems to me that this will put some kind of
>> overhead
>>> in the MINA processing (and maybe memory leaks as well) for a use case
>> that
>>> I don't see being relevant except for 1%
>> What we call a 'session' here is just a container with a state. If the
>> application does not want to do anything with it, no pb.
>>
> What I try to explain is that you are implementing a session for a use case
> that I think is very specific.

Yes, but this is the way the MINA framework is designed : we have
session in the IoHandler...

Now, I wonder if we really need to manage Session instances when we have
incoming UDP messages : wouldn't it be better to propagate a static
Session instance that only contain the scoketAddress from the caller,
taken from a pool of session instances ?

I guess that it's what you have in mind...

>
>> Although it's for Mina a way to gather stats (nv msg sent, etc) and to
>> offer convenient methods (events). Nothing more.
>>
> In my opinion, you are mixing two different aspects.
> The statistics should be available globally for UDP, ie on the port level.

Right. We can probably re-think the way it currently works.

Thanks for the heads up.

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


Re: [MINA 3] UDP support

Posted by Jeff MAURY <je...@jeffmaury.com>.
On Fri, Mar 22, 2013 at 10:05 PM, Emmanuel Lecharny <el...@apache.org>wrote:

> Le 22 mars 2013 21:26, "Jeff MAURY" <je...@jeffmaury.com> a écrit :
> >
> > Sorry, I missed my point.
> > My intent is not to remove the session concept from the MINA UDP API but
> > rather to say that trying to implement the concept of a virtual session
> > like Emmanuel proposes seems to me that this will put some kind of
> overhead
> > in the MINA processing (and maybe memory leaks as well) for a use case
> that
> > I don't see being relevant except for 1%
>
> What we call a 'session' here is just a container with a state. If the
> application does not want to do anything with it, no pb.
>
What I try to explain is that you are implementing a session for a use case
that I think is very specific.

>
> Although it's for Mina a way to gather stats (nv msg sent, etc) and to
> offer convenient methods (events). Nothing more.
>
In my opinion, you are mixing two different aspects.
The statistics should be available globally for UDP, ie on the port level.

>
>
> >
> > Regards
> > Jeff
> >
> >
> >
> > On Fri, Mar 22, 2013 at 9:12 PM, Julien Vermillard <
> jvermillard@gmail.com
> >wrote:
> >
> > > Hi,
> > > comments inline
> > >
> > > On Fri, Mar 22, 2013 at 6:22 PM, Jeff MAURY <je...@jeffmaury.com>
> > > wrote:
> > >
> > > > I don't think we should try to map the session concept on top of UDP.
> It
> > > > think this is something that should be done at the user level.
> > > >
> > >
> > > The whole MINA API is bound the the IoSession how you see UDP servers
> > > without the IoSession ?
> > > Directly read/write on the service ? with only one filter chain ?
> > >
> > > Let me explain a little
> > > > Using UDP, as a server, the only information you have is there is one
> > > > message (and not packet) from this address.
> > > > If you map the session concept based on the remote address, I don"t
> see
> > > how
> > > > this can be handled as UDP does not guaranty the order of the
> messages.
> > > >
> > >
> > > But you can add some IoFilter for doing that: reordering,
> retransmission,
> > > congestion control (well only if you really want to reimplements TCP on
> top
> > > of UDP :)
> > >
> > > So if you want to implement a session, this can be done only on the
> user
> > > > level where you must have something that will mimic what TCP does
> > > > (ordering, retransmission,...).
> > > >
> > > It's perhaps simply a session but with the caracteristic of UDP : not
> in
> > > order, loss of some datagram..
> > >
> > >
> > > > So I would opt for a session-less solution but allowing to retrieve
> > > > information needed (I think this is restricted to the remote socket
> > > > address) to implement sessions on the user level.
> > > >
> > > > WDYT ?
> > > > Jeff
> > > >
> > > >
> > > >
> > > > On Fri, Mar 22, 2013 at 10:53 AM, Emmanuel Lécharny <
> elecharny@gmail.com
> > > > >wrote:
> > > >
> > > > > Hi guys,
> > > > >
> > > > > I'm currently working on the UDP support for MINA 3. Here is the
> way I
> > > > > see the way to implement it, just tell me if you have any better
> idea,
> > > > > suggestion, whatever.
> > > > >
> > > > > First of all, there is a major difference between TCP and UDP : we
> > > don't
> > > > > have to manage an OP_ACCEPT event for UDP. That means we just
> register
> > > > > the socket on a selector for OP_READ events, and we process the
> > > incoming
> > > > > data on the fly.
> > > > >
> > > > > That has one direct consequence : we have to create the sessions
> based
> > > > > on the remote address, and we have to assume that a request coming
> from
> > > > > this remote address is associated with this session (in other
> words, if
> > > > > the server does not close the session, and if we don't manage iddle
> > > > > sessions, we will keep a session for a remote address forever).
> > > > >
> > > > > So the algorithm would be somthing like :
> > > > >
> > > > > select()
> > > > > for each selectionKey selected because of an OP_READ event
> > > > >   do
> > > > >     find the associated session, based on the remote address
> > > > >     if we get one,
> > > > >       then process the data generating a messageReceived event
> > > > >       else
> > > > >         create a new session
> > > > >         send a sessionCreated and sessionOpened event
> > > > >         process the data generating a messageReceived event
> > > > >
> > > > > This is a very rough description of how the main loop works.
> > > > >
> > > > > Some few valuable bits :
> > > > >
> > > > > 1) We need one single thread to manage all the incoming messages.
> The
> > > > > server will register the DatagramChannel on one single selector
> > > anyway...
> > > > > 2) As we use one single thread to process all the incoming
> messages, we
> > > > > wil have to spread the load after having read the data. We will
> need an
> > > > > executor for that (this is not mandatory, but this is the only way
> to
> > > > > scale).
> > > > > As a consequence, assuming we use a pool of thread to manage the
> > > events,
> > > > > we need to guarantee that the messageReceived event is processed
> > > *after*
> > > > > the sessionCreated and sessionOpened events.
> > > > > 3) One idea is to associate an event queue to each sessio. When we
> > > > > create the session, we push three events in this queue : the
> > > > > sessionCreated event, then the sessionOpened one, and finally, the
> > > > > messageReceived event. Then we can peek a thread and let it process
> the
> > > > > events.
> > > > > 4) Or we can associate one single thread to the session ( a bit
> like
> > > > > what is done in MINA 2). It could make sense if we want to order
> the
> > > > > event processing. I prefer the previous solution though.
> > > > >
> > > > > So, wdyt ?
> > > > >
> > > > > --
> > > > > Regards,
> > > > > Cordialement,
> > > > > Emmanuel Lécharny
> > > > > www.iktek.com
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > Jeff MAURY
> > > >
> > > >
> > > > "Legacy code" often differs from its suggested alternative by
> actually
> > > > working and scaling.
> > > >  - Bjarne Stroustrup
> > > >
> > > > http://www.jeffmaury.com
> > > > http://riadiscuss.jeffmaury.com
> > > > http://www.twitter.com/jeffmaury
> > > >
> > >
> >
> >
> >
> > --
> > Jeff MAURY
> >
> >
> > "Legacy code" often differs from its suggested alternative by actually
> > working and scaling.
> >  - Bjarne Stroustrup
> >
> > http://www.jeffmaury.com
> > http://riadiscuss.jeffmaury.com
> > http://www.twitter.com/jeffmaury
>



-- 
Jeff MAURY


"Legacy code" often differs from its suggested alternative by actually
working and scaling.
 - Bjarne Stroustrup

http://www.jeffmaury.com
http://riadiscuss.jeffmaury.com
http://www.twitter.com/jeffmaury

Re: [MINA 3] UDP support

Posted by Emmanuel Lecharny <el...@apache.org>.
Le 22 mars 2013 21:26, "Jeff MAURY" <je...@jeffmaury.com> a écrit :
>
> Sorry, I missed my point.
> My intent is not to remove the session concept from the MINA UDP API but
> rather to say that trying to implement the concept of a virtual session
> like Emmanuel proposes seems to me that this will put some kind of
overhead
> in the MINA processing (and maybe memory leaks as well) for a use case
that
> I don't see being relevant except for 1%

What we call a 'session' here is just a container with a state. If the
application does not want to do anything with it, no pb.

Although it's for Mina a way to gather stats (nv msg sent, etc) and to
offer convenient methods (events). Nothing more.


>
> Regards
> Jeff
>
>
>
> On Fri, Mar 22, 2013 at 9:12 PM, Julien Vermillard <jvermillard@gmail.com
>wrote:
>
> > Hi,
> > comments inline
> >
> > On Fri, Mar 22, 2013 at 6:22 PM, Jeff MAURY <je...@jeffmaury.com>
> > wrote:
> >
> > > I don't think we should try to map the session concept on top of UDP.
It
> > > think this is something that should be done at the user level.
> > >
> >
> > The whole MINA API is bound the the IoSession how you see UDP servers
> > without the IoSession ?
> > Directly read/write on the service ? with only one filter chain ?
> >
> > Let me explain a little
> > > Using UDP, as a server, the only information you have is there is one
> > > message (and not packet) from this address.
> > > If you map the session concept based on the remote address, I don"t
see
> > how
> > > this can be handled as UDP does not guaranty the order of the
messages.
> > >
> >
> > But you can add some IoFilter for doing that: reordering,
retransmission,
> > congestion control (well only if you really want to reimplements TCP on
top
> > of UDP :)
> >
> > So if you want to implement a session, this can be done only on the user
> > > level where you must have something that will mimic what TCP does
> > > (ordering, retransmission,...).
> > >
> > It's perhaps simply a session but with the caracteristic of UDP : not in
> > order, loss of some datagram..
> >
> >
> > > So I would opt for a session-less solution but allowing to retrieve
> > > information needed (I think this is restricted to the remote socket
> > > address) to implement sessions on the user level.
> > >
> > > WDYT ?
> > > Jeff
> > >
> > >
> > >
> > > On Fri, Mar 22, 2013 at 10:53 AM, Emmanuel Lécharny <
elecharny@gmail.com
> > > >wrote:
> > >
> > > > Hi guys,
> > > >
> > > > I'm currently working on the UDP support for MINA 3. Here is the
way I
> > > > see the way to implement it, just tell me if you have any better
idea,
> > > > suggestion, whatever.
> > > >
> > > > First of all, there is a major difference between TCP and UDP : we
> > don't
> > > > have to manage an OP_ACCEPT event for UDP. That means we just
register
> > > > the socket on a selector for OP_READ events, and we process the
> > incoming
> > > > data on the fly.
> > > >
> > > > That has one direct consequence : we have to create the sessions
based
> > > > on the remote address, and we have to assume that a request coming
from
> > > > this remote address is associated with this session (in other
words, if
> > > > the server does not close the session, and if we don't manage iddle
> > > > sessions, we will keep a session for a remote address forever).
> > > >
> > > > So the algorithm would be somthing like :
> > > >
> > > > select()
> > > > for each selectionKey selected because of an OP_READ event
> > > >   do
> > > >     find the associated session, based on the remote address
> > > >     if we get one,
> > > >       then process the data generating a messageReceived event
> > > >       else
> > > >         create a new session
> > > >         send a sessionCreated and sessionOpened event
> > > >         process the data generating a messageReceived event
> > > >
> > > > This is a very rough description of how the main loop works.
> > > >
> > > > Some few valuable bits :
> > > >
> > > > 1) We need one single thread to manage all the incoming messages.
The
> > > > server will register the DatagramChannel on one single selector
> > anyway...
> > > > 2) As we use one single thread to process all the incoming
messages, we
> > > > wil have to spread the load after having read the data. We will
need an
> > > > executor for that (this is not mandatory, but this is the only way
to
> > > > scale).
> > > > As a consequence, assuming we use a pool of thread to manage the
> > events,
> > > > we need to guarantee that the messageReceived event is processed
> > *after*
> > > > the sessionCreated and sessionOpened events.
> > > > 3) One idea is to associate an event queue to each sessio. When we
> > > > create the session, we push three events in this queue : the
> > > > sessionCreated event, then the sessionOpened one, and finally, the
> > > > messageReceived event. Then we can peek a thread and let it process
the
> > > > events.
> > > > 4) Or we can associate one single thread to the session ( a bit like
> > > > what is done in MINA 2). It could make sense if we want to order the
> > > > event processing. I prefer the previous solution though.
> > > >
> > > > So, wdyt ?
> > > >
> > > > --
> > > > Regards,
> > > > Cordialement,
> > > > Emmanuel Lécharny
> > > > www.iktek.com
> > > >
> > > >
> > >
> > >
> > > --
> > > Jeff MAURY
> > >
> > >
> > > "Legacy code" often differs from its suggested alternative by actually
> > > working and scaling.
> > >  - Bjarne Stroustrup
> > >
> > > http://www.jeffmaury.com
> > > http://riadiscuss.jeffmaury.com
> > > http://www.twitter.com/jeffmaury
> > >
> >
>
>
>
> --
> Jeff MAURY
>
>
> "Legacy code" often differs from its suggested alternative by actually
> working and scaling.
>  - Bjarne Stroustrup
>
> http://www.jeffmaury.com
> http://riadiscuss.jeffmaury.com
> http://www.twitter.com/jeffmaury

Re: [MINA 3] UDP support

Posted by Jeff MAURY <je...@jeffmaury.com>.
Sorry, I missed my point.
My intent is not to remove the session concept from the MINA UDP API but
rather to say that trying to implement the concept of a virtual session
like Emmanuel proposes seems to me that this will put some kind of overhead
in the MINA processing (and maybe memory leaks as well) for a use case that
I don't see being relevant except for 1%

Regards
Jeff



On Fri, Mar 22, 2013 at 9:12 PM, Julien Vermillard <jv...@gmail.com>wrote:

> Hi,
> comments inline
>
> On Fri, Mar 22, 2013 at 6:22 PM, Jeff MAURY <je...@jeffmaury.com>
> wrote:
>
> > I don't think we should try to map the session concept on top of UDP. It
> > think this is something that should be done at the user level.
> >
>
> The whole MINA API is bound the the IoSession how you see UDP servers
> without the IoSession ?
> Directly read/write on the service ? with only one filter chain ?
>
> Let me explain a little
> > Using UDP, as a server, the only information you have is there is one
> > message (and not packet) from this address.
> > If you map the session concept based on the remote address, I don"t see
> how
> > this can be handled as UDP does not guaranty the order of the messages.
> >
>
> But you can add some IoFilter for doing that: reordering, retransmission,
> congestion control (well only if you really want to reimplements TCP on top
> of UDP :)
>
> So if you want to implement a session, this can be done only on the user
> > level where you must have something that will mimic what TCP does
> > (ordering, retransmission,...).
> >
> It's perhaps simply a session but with the caracteristic of UDP : not in
> order, loss of some datagram..
>
>
> > So I would opt for a session-less solution but allowing to retrieve
> > information needed (I think this is restricted to the remote socket
> > address) to implement sessions on the user level.
> >
> > WDYT ?
> > Jeff
> >
> >
> >
> > On Fri, Mar 22, 2013 at 10:53 AM, Emmanuel Lécharny <elecharny@gmail.com
> > >wrote:
> >
> > > Hi guys,
> > >
> > > I'm currently working on the UDP support for MINA 3. Here is the way I
> > > see the way to implement it, just tell me if you have any better idea,
> > > suggestion, whatever.
> > >
> > > First of all, there is a major difference between TCP and UDP : we
> don't
> > > have to manage an OP_ACCEPT event for UDP. That means we just register
> > > the socket on a selector for OP_READ events, and we process the
> incoming
> > > data on the fly.
> > >
> > > That has one direct consequence : we have to create the sessions based
> > > on the remote address, and we have to assume that a request coming from
> > > this remote address is associated with this session (in other words, if
> > > the server does not close the session, and if we don't manage iddle
> > > sessions, we will keep a session for a remote address forever).
> > >
> > > So the algorithm would be somthing like :
> > >
> > > select()
> > > for each selectionKey selected because of an OP_READ event
> > >   do
> > >     find the associated session, based on the remote address
> > >     if we get one,
> > >       then process the data generating a messageReceived event
> > >       else
> > >         create a new session
> > >         send a sessionCreated and sessionOpened event
> > >         process the data generating a messageReceived event
> > >
> > > This is a very rough description of how the main loop works.
> > >
> > > Some few valuable bits :
> > >
> > > 1) We need one single thread to manage all the incoming messages. The
> > > server will register the DatagramChannel on one single selector
> anyway...
> > > 2) As we use one single thread to process all the incoming messages, we
> > > wil have to spread the load after having read the data. We will need an
> > > executor for that (this is not mandatory, but this is the only way to
> > > scale).
> > > As a consequence, assuming we use a pool of thread to manage the
> events,
> > > we need to guarantee that the messageReceived event is processed
> *after*
> > > the sessionCreated and sessionOpened events.
> > > 3) One idea is to associate an event queue to each sessio. When we
> > > create the session, we push three events in this queue : the
> > > sessionCreated event, then the sessionOpened one, and finally, the
> > > messageReceived event. Then we can peek a thread and let it process the
> > > events.
> > > 4) Or we can associate one single thread to the session ( a bit like
> > > what is done in MINA 2). It could make sense if we want to order the
> > > event processing. I prefer the previous solution though.
> > >
> > > So, wdyt ?
> > >
> > > --
> > > Regards,
> > > Cordialement,
> > > Emmanuel Lécharny
> > > www.iktek.com
> > >
> > >
> >
> >
> > --
> > Jeff MAURY
> >
> >
> > "Legacy code" often differs from its suggested alternative by actually
> > working and scaling.
> >  - Bjarne Stroustrup
> >
> > http://www.jeffmaury.com
> > http://riadiscuss.jeffmaury.com
> > http://www.twitter.com/jeffmaury
> >
>



-- 
Jeff MAURY


"Legacy code" often differs from its suggested alternative by actually
working and scaling.
 - Bjarne Stroustrup

http://www.jeffmaury.com
http://riadiscuss.jeffmaury.com
http://www.twitter.com/jeffmaury

Re: [MINA 3] UDP support

Posted by Julien Vermillard <jv...@gmail.com>.
Hi,
comments inline

On Fri, Mar 22, 2013 at 6:22 PM, Jeff MAURY <je...@jeffmaury.com> wrote:

> I don't think we should try to map the session concept on top of UDP. It
> think this is something that should be done at the user level.
>

The whole MINA API is bound the the IoSession how you see UDP servers
without the IoSession ?
Directly read/write on the service ? with only one filter chain ?

Let me explain a little
> Using UDP, as a server, the only information you have is there is one
> message (and not packet) from this address.
> If you map the session concept based on the remote address, I don"t see how
> this can be handled as UDP does not guaranty the order of the messages.
>

But you can add some IoFilter for doing that: reordering, retransmission,
congestion control (well only if you really want to reimplements TCP on top
of UDP :)

So if you want to implement a session, this can be done only on the user
> level where you must have something that will mimic what TCP does
> (ordering, retransmission,...).
>
It's perhaps simply a session but with the caracteristic of UDP : not in
order, loss of some datagram..


> So I would opt for a session-less solution but allowing to retrieve
> information needed (I think this is restricted to the remote socket
> address) to implement sessions on the user level.
>
> WDYT ?
> Jeff
>
>
>
> On Fri, Mar 22, 2013 at 10:53 AM, Emmanuel Lécharny <elecharny@gmail.com
> >wrote:
>
> > Hi guys,
> >
> > I'm currently working on the UDP support for MINA 3. Here is the way I
> > see the way to implement it, just tell me if you have any better idea,
> > suggestion, whatever.
> >
> > First of all, there is a major difference between TCP and UDP : we don't
> > have to manage an OP_ACCEPT event for UDP. That means we just register
> > the socket on a selector for OP_READ events, and we process the incoming
> > data on the fly.
> >
> > That has one direct consequence : we have to create the sessions based
> > on the remote address, and we have to assume that a request coming from
> > this remote address is associated with this session (in other words, if
> > the server does not close the session, and if we don't manage iddle
> > sessions, we will keep a session for a remote address forever).
> >
> > So the algorithm would be somthing like :
> >
> > select()
> > for each selectionKey selected because of an OP_READ event
> >   do
> >     find the associated session, based on the remote address
> >     if we get one,
> >       then process the data generating a messageReceived event
> >       else
> >         create a new session
> >         send a sessionCreated and sessionOpened event
> >         process the data generating a messageReceived event
> >
> > This is a very rough description of how the main loop works.
> >
> > Some few valuable bits :
> >
> > 1) We need one single thread to manage all the incoming messages. The
> > server will register the DatagramChannel on one single selector anyway...
> > 2) As we use one single thread to process all the incoming messages, we
> > wil have to spread the load after having read the data. We will need an
> > executor for that (this is not mandatory, but this is the only way to
> > scale).
> > As a consequence, assuming we use a pool of thread to manage the events,
> > we need to guarantee that the messageReceived event is processed *after*
> > the sessionCreated and sessionOpened events.
> > 3) One idea is to associate an event queue to each sessio. When we
> > create the session, we push three events in this queue : the
> > sessionCreated event, then the sessionOpened one, and finally, the
> > messageReceived event. Then we can peek a thread and let it process the
> > events.
> > 4) Or we can associate one single thread to the session ( a bit like
> > what is done in MINA 2). It could make sense if we want to order the
> > event processing. I prefer the previous solution though.
> >
> > So, wdyt ?
> >
> > --
> > Regards,
> > Cordialement,
> > Emmanuel Lécharny
> > www.iktek.com
> >
> >
>
>
> --
> Jeff MAURY
>
>
> "Legacy code" often differs from its suggested alternative by actually
> working and scaling.
>  - Bjarne Stroustrup
>
> http://www.jeffmaury.com
> http://riadiscuss.jeffmaury.com
> http://www.twitter.com/jeffmaury
>

Re: [MINA 3] UDP support

Posted by Emmanuel Lecharny <el...@apache.org>.
Le 22 mars 2013 18:23, "Jeff MAURY" <je...@jeffmaury.com> a écrit :
>
> I don't think we should try to map the session concept on top of UDP. It
> think this is something that should be done at the user level.

Just fyi, this is what we already do since mina 1.

> Let me explain a little
> Using UDP, as a server, the only information you have is there is one
> message (and not packet) from this address.
> If you map the session concept based on the remote address, I don"t see
how
> this can be handled as UDP does not guaranty the order of the messages.

UDP does guarantee that a datagram will either be sent fully,  or
discarded. From the user POV, as a datagram size is limited to 64k (and it
depends on the OS), if a bigger size has to be sent, it's up to the client
and the server to manage the ordering. Ie, it has to be handled by the
application protocol.

Her, the session has a different meaning. It's semantically another beast.
However we can perfectly create such a session, assuming that the end
points know how to deal with it.

> So if you want to implement a session, this can be done only on the user
> level where you must have something that will mimic what TCP does
> (ordering, retransmission,...).

Absolutely. Here, we already create a session, which may not be used at all.

> So I would opt for a session-less solution but allowing to retrieve
> information needed (I think this is restricted to the remote socket
> address) to implement sessions on the user level.

Well, thus is pretty much what we do... But we can be smarter. For
instance, managing the session idleness often does not make sense in UDP.

Now, the base idea behind Mina is to hide all the plumbery so that the user
does not even have to know he is UDP or TCP based. Typically, this is what
we do on kerberos : the protocol switch from tcp to udp, but neither the
client nor the server care. They still do a session.write(message) to send
requests/responses. And that'S Rreally cool :)

>
> WDYT ?
> Jeff
>
>
>
> On Fri, Mar 22, 2013 at 10:53 AM, Emmanuel Lécharny <elecharny@gmail.com
>wrote:
>
> > Hi guys,
> >
> > I'm currently working on the UDP support for MINA 3. Here is the way I
> > see the way to implement it, just tell me if you have any better idea,
> > suggestion, whatever.
> >
> > First of all, there is a major difference between TCP and UDP : we don't
> > have to manage an OP_ACCEPT event for UDP. That means we just register
> > the socket on a selector for OP_READ events, and we process the incoming
> > data on the fly.
> >
> > That has one direct consequence : we have to create the sessions based
> > on the remote address, and we have to assume that a request coming from
> > this remote address is associated with this session (in other words, if
> > the server does not close the session, and if we don't manage iddle
> > sessions, we will keep a session for a remote address forever).
> >
> > So the algorithm would be somthing like :
> >
> > select()
> > for each selectionKey selected because of an OP_READ event
> >   do
> >     find the associated session, based on the remote address
> >     if we get one,
> >       then process the data generating a messageReceived event
> >       else
> >         create a new session
> >         send a sessionCreated and sessionOpened event
> >         process the data generating a messageReceived event
> >
> > This is a very rough description of how the main loop works.
> >
> > Some few valuable bits :
> >
> > 1) We need one single thread to manage all the incoming messages. The
> > server will register the DatagramChannel on one single selector
anyway...
> > 2) As we use one single thread to process all the incoming messages, we
> > wil have to spread the load after having read the data. We will need an
> > executor for that (this is not mandatory, but this is the only way to
> > scale).
> > As a consequence, assuming we use a pool of thread to manage the events,
> > we need to guarantee that the messageReceived event is processed *after*
> > the sessionCreated and sessionOpened events.
> > 3) One idea is to associate an event queue to each sessio. When we
> > create the session, we push three events in this queue : the
> > sessionCreated event, then the sessionOpened one, and finally, the
> > messageReceived event. Then we can peek a thread and let it process the
> > events.
> > 4) Or we can associate one single thread to the session ( a bit like
> > what is done in MINA 2). It could make sense if we want to order the
> > event processing. I prefer the previous solution though.
> >
> > So, wdyt ?
> >
> > --
> > Regards,
> > Cordialement,
> > Emmanuel Lécharny
> > www.iktek.com
> >
> >
>
>
> --
> Jeff MAURY
>
>
> "Legacy code" often differs from its suggested alternative by actually
> working and scaling.
>  - Bjarne Stroustrup
>
> http://www.jeffmaury.com
> http://riadiscuss.jeffmaury.com
> http://www.twitter.com/jeffmaury

Re: [MINA 3] UDP support

Posted by Jeff MAURY <je...@jeffmaury.com>.
I don't think we should try to map the session concept on top of UDP. It
think this is something that should be done at the user level.
Let me explain a little
Using UDP, as a server, the only information you have is there is one
message (and not packet) from this address.
If you map the session concept based on the remote address, I don"t see how
this can be handled as UDP does not guaranty the order of the messages.
So if you want to implement a session, this can be done only on the user
level where you must have something that will mimic what TCP does
(ordering, retransmission,...).
So I would opt for a session-less solution but allowing to retrieve
information needed (I think this is restricted to the remote socket
address) to implement sessions on the user level.

WDYT ?
Jeff



On Fri, Mar 22, 2013 at 10:53 AM, Emmanuel Lécharny <el...@gmail.com>wrote:

> Hi guys,
>
> I'm currently working on the UDP support for MINA 3. Here is the way I
> see the way to implement it, just tell me if you have any better idea,
> suggestion, whatever.
>
> First of all, there is a major difference between TCP and UDP : we don't
> have to manage an OP_ACCEPT event for UDP. That means we just register
> the socket on a selector for OP_READ events, and we process the incoming
> data on the fly.
>
> That has one direct consequence : we have to create the sessions based
> on the remote address, and we have to assume that a request coming from
> this remote address is associated with this session (in other words, if
> the server does not close the session, and if we don't manage iddle
> sessions, we will keep a session for a remote address forever).
>
> So the algorithm would be somthing like :
>
> select()
> for each selectionKey selected because of an OP_READ event
>   do
>     find the associated session, based on the remote address
>     if we get one,
>       then process the data generating a messageReceived event
>       else
>         create a new session
>         send a sessionCreated and sessionOpened event
>         process the data generating a messageReceived event
>
> This is a very rough description of how the main loop works.
>
> Some few valuable bits :
>
> 1) We need one single thread to manage all the incoming messages. The
> server will register the DatagramChannel on one single selector anyway...
> 2) As we use one single thread to process all the incoming messages, we
> wil have to spread the load after having read the data. We will need an
> executor for that (this is not mandatory, but this is the only way to
> scale).
> As a consequence, assuming we use a pool of thread to manage the events,
> we need to guarantee that the messageReceived event is processed *after*
> the sessionCreated and sessionOpened events.
> 3) One idea is to associate an event queue to each sessio. When we
> create the session, we push three events in this queue : the
> sessionCreated event, then the sessionOpened one, and finally, the
> messageReceived event. Then we can peek a thread and let it process the
> events.
> 4) Or we can associate one single thread to the session ( a bit like
> what is done in MINA 2). It could make sense if we want to order the
> event processing. I prefer the previous solution though.
>
> So, wdyt ?
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.iktek.com
>
>


-- 
Jeff MAURY


"Legacy code" often differs from its suggested alternative by actually
working and scaling.
 - Bjarne Stroustrup

http://www.jeffmaury.com
http://riadiscuss.jeffmaury.com
http://www.twitter.com/jeffmaury