You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by tiandike <wh...@21cn.com> on 2007/09/26 18:03:14 UTC

Do i need to use threadpool in my iohandler to improve performance?

thanks!
-- 
View this message in context: http://www.nabble.com/Do-i-need-to-use-threadpool-in-my-iohandler-to-improve-performance--tf4523297s16868.html#a12904139
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: Do i need to use threadpool in my iohandler to improve performance?

Posted by Trustin Lee <tr...@gmail.com>.
On 9/28/07, tiandike <wh...@21cn.com> wrote:
>
> as you said "For an application with a ProtocolCodecFilter implemetation and
> a
> usual IoHandler implementation with database operations, I'd suggest
> you to add the ExecutorFilter after the ProtocolCodecFilter
> implementation. "
>
> do you mean:
>
> cfg.getFilterChain().addLast(
>                 "codec",
>                 new ProtocolCodecFilter(new TextLineCodecFactory(Charset
>                         .forName("UTF-8"))));
>
> cfg.getFilterChain().addLast("threadPool", new
> ExecutorFilter(Executors.newCachedThreadPool()));
>
> ??
>
> if i put ExecutorFilter before ProtocolCodecFilter  , do it has the same
> effect?

No.  ExecutorFilter is usually put after ProtocolCodecFilter, because
it is often optimal for a codec code to run in the same thread with
the I/O thread.

Adding an ExecutorFilter before ProtocolCodecFilter, your codec code
runs in a different thread from the I/O threads.

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

Re: Do i need to use threadpool in my iohandler to improve performance?

Posted by tiandike <wh...@21cn.com>.
as you said "For an application with a ProtocolCodecFilter implemetation and
a
usual IoHandler implementation with database operations, I'd suggest
you to add the ExecutorFilter after the ProtocolCodecFilter
implementation. "

do you mean:

cfg.getFilterChain().addLast(
                "codec",
                new ProtocolCodecFilter(new TextLineCodecFactory(Charset
                        .forName("UTF-8"))));

cfg.getFilterChain().addLast("threadPool", new
ExecutorFilter(Executors.newCachedThreadPool()));

??

if i put ExecutorFilter before ProtocolCodecFilter  , do it has the same
effect?



Maarten Bosteels-4 wrote:
> 
> On 9/28/07, tiandike <wh...@21cn.com> wrote:
>>
>> if i use ProtocolCodecFilter  , do ExecutorFilter in the filterchain?
> 
> ProtocolCodecFilter and ExecutorFilter are orthogonal features
> 
> You can use one without the other, or both together.
> You can put the ExecutorFilter before or after the ProtocolCodecFilter,
> ...
> 
> In MINA 2.0 it should also be possible to have more than one
> ProtocolCodecFilter
> 
> It all depends on what you want to achieve.
> Have you read this : http://mina.apache.org/configuring-thread-model.html
> 
> "For an application with a ProtocolCodecFilter implemetation and a
> usual IoHandler implementation with database operations, I'd suggest
> you to add the ExecutorFilter after the ProtocolCodecFilter
> implementation. It is because the performance characteristic of most
> protocol codec implementations is CPU-bound, which is the same with
> I/O processor threads."
> 
> Maarten
> 
>>
>>
>> Maarten Bosteels-4 wrote:
>> >
>> > It's unlikely that anyone can give a good answer to such a generic
>> > question.
>> >
>> > 1) It depends highly on the type of application you are writing.
>> > 2) Instead of using your own thread-pool, you could also add an
>> > ExecutorFilter to the chain
>> > for example at the end (thus just before your IoHandler)
>> > 3) testing performance of the alternatives will give you the best
>> answer
>> >
>> > regards,
>> > Maarten
>> >
>> > On 9/26/07, tiandike <wh...@21cn.com> wrote:
>> >>
>> >> thanks!
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/Do-i-need-to-use-threadpool-in-my-iohandler-to-improve-performance--tf4523297s16868.html#a12904139
>> >> Sent from the Apache MINA Support Forum mailing list archive at
>> >> Nabble.com.
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Do-i-need-to-use-threadpool-in-my-iohandler-to-improve-performance--tf4523297s16868.html#a12937529
>> Sent from the Apache MINA Support Forum mailing list archive at
>> Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Do-i-need-to-use-threadpool-in-my-iohandler-to-improve-performance--tf4523297s16868.html#a12939086
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: Do i need to use threadpool in my iohandler to improve performance?

Posted by Maarten Bosteels <mb...@gmail.com>.
On 9/28/07, tiandike <wh...@21cn.com> wrote:
>
> if i use ProtocolCodecFilter  , do ExecutorFilter in the filterchain?

ProtocolCodecFilter and ExecutorFilter are orthogonal features

You can use one without the other, or both together.
You can put the ExecutorFilter before or after the ProtocolCodecFilter, ...

In MINA 2.0 it should also be possible to have more than one ProtocolCodecFilter

It all depends on what you want to achieve.
Have you read this : http://mina.apache.org/configuring-thread-model.html

"For an application with a ProtocolCodecFilter implemetation and a
usual IoHandler implementation with database operations, I'd suggest
you to add the ExecutorFilter after the ProtocolCodecFilter
implementation. It is because the performance characteristic of most
protocol codec implementations is CPU-bound, which is the same with
I/O processor threads."

Maarten

>
>
> Maarten Bosteels-4 wrote:
> >
> > It's unlikely that anyone can give a good answer to such a generic
> > question.
> >
> > 1) It depends highly on the type of application you are writing.
> > 2) Instead of using your own thread-pool, you could also add an
> > ExecutorFilter to the chain
> > for example at the end (thus just before your IoHandler)
> > 3) testing performance of the alternatives will give you the best answer
> >
> > regards,
> > Maarten
> >
> > On 9/26/07, tiandike <wh...@21cn.com> wrote:
> >>
> >> thanks!
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Do-i-need-to-use-threadpool-in-my-iohandler-to-improve-performance--tf4523297s16868.html#a12904139
> >> Sent from the Apache MINA Support Forum mailing list archive at
> >> Nabble.com.
> >>
> >>
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Do-i-need-to-use-threadpool-in-my-iohandler-to-improve-performance--tf4523297s16868.html#a12937529
> Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.
>
>

Re: Do i need to use threadpool in my iohandler to improve performance?

Posted by tiandike <wh...@21cn.com>.
if i use ProtocolCodecFilter  , do ExecutorFilter in the filterchain?


Maarten Bosteels-4 wrote:
> 
> It's unlikely that anyone can give a good answer to such a generic
> question.
> 
> 1) It depends highly on the type of application you are writing.
> 2) Instead of using your own thread-pool, you could also add an
> ExecutorFilter to the chain
> for example at the end (thus just before your IoHandler)
> 3) testing performance of the alternatives will give you the best answer
> 
> regards,
> Maarten
> 
> On 9/26/07, tiandike <wh...@21cn.com> wrote:
>>
>> thanks!
>> --
>> View this message in context:
>> http://www.nabble.com/Do-i-need-to-use-threadpool-in-my-iohandler-to-improve-performance--tf4523297s16868.html#a12904139
>> Sent from the Apache MINA Support Forum mailing list archive at
>> Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Do-i-need-to-use-threadpool-in-my-iohandler-to-improve-performance--tf4523297s16868.html#a12937529
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: Do i need to use threadpool in my iohandler to improve performance?

Posted by Maarten Bosteels <mb...@gmail.com>.
It's unlikely that anyone can give a good answer to such a generic question.

1) It depends highly on the type of application you are writing.
2) Instead of using your own thread-pool, you could also add an
ExecutorFilter to the chain
for example at the end (thus just before your IoHandler)
3) testing performance of the alternatives will give you the best answer

regards,
Maarten

On 9/26/07, tiandike <wh...@21cn.com> wrote:
>
> thanks!
> --
> View this message in context: http://www.nabble.com/Do-i-need-to-use-threadpool-in-my-iohandler-to-improve-performance--tf4523297s16868.html#a12904139
> Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.
>
>