You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by mat <fo...@gmail.com> on 2007/04/19 03:21:19 UTC

Business Logic

Dear all,

I am using mina as both server and client in my service. I just wonder if I
should use IO/service(process) threads provided by mina to handle the
business logic?
what I understood is:
I added config.getFilterChain().addLast("threadPool", new ExecutorFilter(
Executors.newCachedThreadPool())) at server.

1) If client connector also needs config.getFilterChain().addLast("threadPool",
new ExecutorFilter(Executors.newCachedThreadPool())) ? If so, how to control
the numbers of threads for both servers and clients in order to reach the
maxiuam performance. I have 4, 5 client connections.

2) Since in my application, the data is big. What if mina IO/Process CAN'T
handle them in time? Put them in the mina internal queue? Or drop them? I
really worry about the memory problem.

3) If i use IO/process threads, the messageReceived methods will be called
asychronized. Am I right? If so, how can I make sure the incoming events is
processed in order?

Thanks.

Re: Business Logic

Posted by mat <fo...@gmail.com>.
2007/4/19, mat <fo...@gmail.com>:
>
> Hi Trustin
>
> Thanks for your answers alwayd in detail. Congralution to your marriage.
> Are you in Korea now? Actually I have some business parnters IT guys living
> in seoul and i visited there last year. Please see * for my question below.
>
> Mat
>
> 2007/4/19, Trustin Lee <tr...@gmail.com>:
> >
> > Hi mat,
> >
> > On 4/19/07, mat <fo...@gmail.com> wrote:
> > > Dear all,
> > >
> > > I am using mina as both server and client in my service. I just wonder
> > if I
> > > should use IO/service(process) threads provided by mina to handle the
> > > business logic?
> > > what I understood is:
> > > I added config.getFilterChain().addLast("threadPool", new
> > ExecutorFilter(
> > > Executors.newCachedThreadPool())) at server.
> >
> > There's no direct relationship between implementing business logic and
> > adding an executor filter to the filter chain.  You can execute the
> > business logic in your IoHandler even if you didn't add an executor
> > filter.  An executor filter is required only the the business logic
> > performs a blocking operation such as database access.
> >
> > Probably most business logic will involve external resources like
> > database, you are likely to add an executor filter.
> >
> > > 1) If client connector also needs config.getFilterChain
> > ().addLast("threadPool",
> > > new ExecutorFilter(Executors.newCachedThreadPool())) ? If so, how to
> > control
> > > the numbers of threads for both servers and clients in order to reach
> > the
> > > maxiuam performance. I have 4, 5 client connections.
> >
> > If you want to control the maximum number of threads, you will have to
> > create a different Executor that just
> > 'Executors.newCachedThreadPool()'.  You need to consult the JavaDoc of
> > java.util.concurrent.Executors class.
> >
> > MINA executor filter ensures only one event is processed per session,
> > so you will have 5 active thread at max even if you used
> > Executors.newCachedThreadPool().
> >
> > Again, creating an executor is what MINA does but you do.  Please
> > check the Java SE API documentation.
>
>
> * In your tutorial, you suggested number of processor + 1 thread. However,
> my applicaiton has 1 server and 5, 6 clients in one process. If my server
> acceptor follows this rule, how about my client connectos?
> * In the tutorial, Executors.newCachedThreadPool() is always preferred by IoService?
> I am confused.
>

I read the tutorial again.  Executors.newCachedThreadPool() is for
IOService, now i understood this. IOService thread is same as 'IOProcessor
thread' right?


> > 2) Since in my application, the data is big. What if mina IO/Process
> CAN'T
> > handle them in time? Put them in the mina internal queue? Or drop them?
> I
> > really worry about the memory problem.
>
> If the data is too big to load the whole data into the heap, things
> become tricky.  People usually split the big data into multiple
> messages.
>
> * when I said 'big', i meant 'fast' and huge data.
>
> > 3) If i use IO/process threads, the messageReceived methods will be
> > called
> > > asychronized. Am I right? If so, how can I make sure the incoming
> > events is
> > > processed in order?
> >
> > I don't get your question here.  MINA can't do anything without I/O
> > processor threads.
>
>
> *   We didn't add any ExecutorFilter so far. If no ExecutorFilter is
> added, events are forwarded to an IoHandler via method invocations. This
> means your business logic in your IoHandler
> * implementation will run in the I/O processor thread. We call this thread
> model a '*single thread model*'. (from tutorial)
> *  Actually i am making a Gateway bypassing the message, the job of
> Gateway one side(client connectors 5, 6)  is decoding or encoding messages,
> the other side is server which handles end clients.
> * So I don't need to add an ExecutorFilter, do I? If I have one IO
> processor thread, which means the thread must do the decode and also handle
> the message routing?
>
> Anyway, the order of events is always maintained correctly.  You don't
> > need to worry one message arrives before the other arrives.
> >
> > Trustin
> > --
> > what we call human nature is actually human habit
> > --
> > http://gleamynode.net/
> > --
> > PGP Key ID: 0x0255ECA6
> >
>
>

Re: Business Logic

Posted by mat <fo...@gmail.com>.
Hi Trustin

Thanks for your answers alwayd in detail. Congralution to your marriage.
Are you in Korea now? Actually I have some business parnters IT guys living
in seoul and i visited there last year. Please see * for my question below.

Mat

2007/4/19, Trustin Lee <tr...@gmail.com>:
>
> Hi mat,
>
> On 4/19/07, mat <fo...@gmail.com> wrote:
> > Dear all,
> >
> > I am using mina as both server and client in my service. I just wonder
> if I
> > should use IO/service(process) threads provided by mina to handle the
> > business logic?
> > what I understood is:
> > I added config.getFilterChain().addLast("threadPool", new
> ExecutorFilter(
> > Executors.newCachedThreadPool())) at server.
>
> There's no direct relationship between implementing business logic and
> adding an executor filter to the filter chain.  You can execute the
> business logic in your IoHandler even if you didn't add an executor
> filter.  An executor filter is required only the the business logic
> performs a blocking operation such as database access.
>
> Probably most business logic will involve external resources like
> database, you are likely to add an executor filter.
>
> > 1) If client connector also needs config.getFilterChain
> ().addLast("threadPool",
> > new ExecutorFilter(Executors.newCachedThreadPool())) ? If so, how to
> control
> > the numbers of threads for both servers and clients in order to reach
> the
> > maxiuam performance. I have 4, 5 client connections.
>
> If you want to control the maximum number of threads, you will have to
> create a different Executor that just
> 'Executors.newCachedThreadPool()'.  You need to consult the JavaDoc of
> java.util.concurrent.Executors class.
>
> MINA executor filter ensures only one event is processed per session,
> so you will have 5 active thread at max even if you used
> Executors.newCachedThreadPool().
>
> Again, creating an executor is what MINA does but you do.  Please
> check the Java SE API documentation.


* In your tutorial, you suggested number of processor + 1 thread. However,
my applicaiton has 1 server and 5, 6 clients in one process. If my server
acceptor follows this rule, how about my client connectos?
* In the tutorial, Executors.newCachedThreadPool() is always preferred
by IoService?
I am confused.

> 2) Since in my application, the data is big. What if mina IO/Process CAN'T
> handle them in time? Put them in the mina internal queue? Or drop them? I
> really worry about the memory problem.

If the data is too big to load the whole data into the heap, things
become tricky.  People usually split the big data into multiple
messages.

* when I said 'big', i meant 'fast' and huge data.

> 3) If i use IO/process threads, the messageReceived methods will be called
> > asychronized. Am I right? If so, how can I make sure the incoming events
> is
> > processed in order?
>
> I don't get your question here.  MINA can't do anything without I/O
> processor threads.


*   We didn't add any ExecutorFilter so far. If no ExecutorFilter is added,
events are forwarded to an IoHandler via method invocations. This means your
business logic in your IoHandler
* implementation will run in the I/O processor thread. We call this thread
model a '*single thread model*'. (from tutorial)
*  Actually i am making a Gateway bypassing the message, the job of Gateway
one side(client connectors 5, 6)  is decoding or encoding messages, the
other side is server which handles end clients.
* So I don't need to add an ExecutorFilter, do I?

Anyway, the order of events is always maintained correctly.  You don't
> need to worry one message arrives before the other arrives.
>
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
>

Re: Business Logic

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

On 4/19/07, mat <fo...@gmail.com> wrote:
> Dear all,
>
> I am using mina as both server and client in my service. I just wonder if I
> should use IO/service(process) threads provided by mina to handle the
> business logic?
> what I understood is:
> I added config.getFilterChain().addLast("threadPool", new ExecutorFilter(
> Executors.newCachedThreadPool())) at server.

There's no direct relationship between implementing business logic and
adding an executor filter to the filter chain.  You can execute the
business logic in your IoHandler even if you didn't add an executor
filter.  An executor filter is required only the the business logic
performs a blocking operation such as database access.

Probably most business logic will involve external resources like
database, you are likely to add an executor filter.

> 1) If client connector also needs config.getFilterChain().addLast("threadPool",
> new ExecutorFilter(Executors.newCachedThreadPool())) ? If so, how to control
> the numbers of threads for both servers and clients in order to reach the
> maxiuam performance. I have 4, 5 client connections.

If you want to control the maximum number of threads, you will have to
create a different Executor that just
'Executors.newCachedThreadPool()'.  You need to consult the JavaDoc of
java.util.concurrent.Executors class.

MINA executor filter ensures only one event is processed per session,
so you will have 5 active thread at max even if you used
Executors.newCachedThreadPool().

Again, creating an executor is what MINA does but you do.  Please
check the Java SE API documentation.

> 2) Since in my application, the data is big. What if mina IO/Process CAN'T
> handle them in time? Put them in the mina internal queue? Or drop them? I
> really worry about the memory problem.

If the data is too big to load the whole data into the heap, things
become tricky.  People usually split the big data into multiple
messages.

> 3) If i use IO/process threads, the messageReceived methods will be called
> asychronized. Am I right? If so, how can I make sure the incoming events is
> processed in order?

I don't get your question here.  MINA can't do anything without I/O
processor threads.

Anyway, the order of events is always maintained correctly.  You don't
need to worry one message arrives before the other arrives.

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