You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Pérez Paz Luis Alberto <la...@banxico.org.mx> on 2007/04/24 01:09:57 UTC
MINA Executors Usage
Hi MINA community,
I'm programming a server with mina 1.0.3, in order to attend concurrent clients I'm trying to have a good Executors usage.
I would appreciate your opinion about this model:
1) I disabled the default thread model setting and I added a newCachedThreadPool in the I/O Layer:
cfg.setThreadModel(ThreadModel.MANUAL);
IoAcceptor acceptor = new SocketAcceptor( IO_THREADS, Executors.newCachedThreadPool()); // IO_THREADS = NUMBER_CPU + 1
2) I added an ExecutorFilter to the IoFilterChain. I wrote my own Executor Services/Thread Factory, according to the pool sizes, queuing, queuing policy....basically I got 3 categories: IOThreadPool, CPUThreadPool and LowPriorityThreadPool. I chose a CPUThreadPool in the related Filter. (which is added after the ProtocolCodecFilter).
cfg.getFilterChain().addLast("THREADPOOL", new ExecutorFilter( MyExecutors.CPUThreadPool ));
3) Finally, in my IoHandlerAdapter implementation, in accordance with the kind of task I launch threads.
public void messageReceived( IoSession session, Object message )
{
if ( message instanceof DBMsg )
{
...
MyExecutors.IOThreadPool.execute(new RunnableDBTask(data) );
...
}
if ( message instanceof LowPriorityMsg )
{
...
MyExecutors.LowPriorityThreadPool.execute(new RunnableLPTask(data) );
...
}
Is it a good idea/practice?
Thanks in advance.
Best Regards,
Re: MINA Executors Usage
Posted by peter royal <pr...@apache.org>.
On Apr 23, 2007, at 4:09 PM, Pérez Paz Luis Alberto wrote:
> 1) I disabled the default thread model setting and I added a
> newCachedThreadPool in the I/O Layer:
>
>
>
> cfg.setThreadModel(ThreadModel.MANUAL);
>
> IoAcceptor acceptor = new SocketAcceptor( IO_THREADS,
> Executors.newCachedThreadPool()); // IO_THREADS =
> NUMBER_CPU + 1
good
> 2) I added an ExecutorFilter to the IoFilterChain. I wrote my own
> Executor Services/Thread Factory, according to the pool sizes,
> queuing, queuing policy....basically I got 3 categories:
> IOThreadPool, CPUThreadPool and LowPriorityThreadPool. I chose a
> CPUThreadPool in the related Filter. (which is added after the
> ProtocolCodecFilter).
>
>
>
> cfg.getFilterChain().addLast("THREADPOOL", new ExecutorFilter
> ( MyExecutors.CPUThreadPool ));
sounds good. nice to see one making use of the pluggable Executor
policy :)
> 3) Finally, in my IoHandlerAdapter implementation, in accordance
> with the kind of task I launch threads.
since you already have an ExecutorFilter, it seems kinda redundant to
launch more threads here.. but it may make sense for your
application, given the small bit of pseudo-code you laid out.
-pete
--
proyal@apache.org - http://fotap.org/~osi