You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Messi Chan <ch...@gmail.com> on 2007/06/07 09:24:56 UTC

How could I set thread pool for IoServices and ExecutorFilters?

Hi, all
I have read this article 
http://mina.apache.org/configuring-thread-model.html
http://mina.apache.org/configuring-thread-model.html . At the end of the
article, author suggest us not share one thread pool for IoServices and
ExecutorFilters, and better to use a cached thread pool for IoServices.

Is that means if I add only one thread pool to IoFilterChain, then the  I/O
processor would acquire a thread from the shared pool? So, adding two thread
pools would be OK? like below. 

SocketAcceptorConfig config = (SocketAcceptorConfig)
acceptor.getDefaultConfig();
config.setThreadModel(ThreadModel.MANUAL);
ExecutorService executor1 = Executors.newCachedThreadPool();
config.getFilterChain().addLast("pool1", new ExecutorFilter(executor1));
ExecutorService executor2 = Executors.newCachedThreadPool();
config.getFilterChain().addLast("pool2", new ExecutorFilter(executor2));

Am I right? if wrong, how?

thx a lot!


-- 
View this message in context: http://www.nabble.com/How-could-I-set-thread-pool-for-IoServices-and-ExecutorFilters--tf3882251.html#a11003189
Sent from the mina dev mailing list archive at Nabble.com.


Re: How could I set thread pool for IoServices and ExecutorFilters?

Posted by Niklas Therning <ni...@trillian.se>.
Messi Chan wrote:
> Thx, Trustin.
>
>
> Now I have an other newbie question. 
> It's about the integrality of the message sent by socket. When I used TCP
> connection, 
> does the message been ensured its integrality. Is that to say, the message
> won't been cut down or changed during it's passing through internet? 
> need I validate their CRC code to make sure their integrality? Or other way?
> Or maybe I have not to worried about it?
>
> thx a lot :D
>   

A chunk of bytes sent by the client may be sliced up into smaller chunks
or merged with other chunks into a single larger chunk. That's the way
TCP works. Have a look in the FAQ:
http://mina.apache.org/faq.html#FAQ-WhydoesSocketConnectorsendseveralmessagesasonemessage?

TCP provides reliable and in-order delivery of data so you shouldn't
have to worry about the integrity in most cases. However, in cannot
protect you against man-in-the-middle attacks. If your data is sensitive
and sent over untrusted networks, SSL or similar protocols will protect
your data and guarantee its integrity. MINA has an SSLFilter which you
can use in that case.

HTH

-- 
Niklas Therning
www.spamdrain.net


Re: How could I set thread pool for IoServices and ExecutorFilters?

Posted by Messi Chan <ch...@gmail.com>.
Thx, Trustin.


Now I have an other newbie question. 
It's about the integrality of the message sent by socket. When I used TCP
connection, 
does the message been ensured its integrality. Is that to say, the message
won't been cut down or changed during it's passing through internet? 
need I validate their CRC code to make sure their integrality? Or other way?
Or maybe I have not to worried about it?

thx a lot :D
-- 
View this message in context: http://www.nabble.com/How-could-I-set-thread-pool-for-IoServices-and-ExecutorFilters--tf3882251.html#a11020868
Sent from the mina dev mailing list archive at Nabble.com.


Re: How could I set thread pool for IoServices and ExecutorFilters?

Posted by Trustin Lee <tr...@gmail.com>.
On 6/7/07, Messi Chan <ch...@gmail.com> wrote:
>
> Hi, Trustin, thx for your reply.
>
> According to your advice, I modify those codes below:
>
> ExecutorService executor1 = Executors.newCachedThreadPool();
> SocketAcceptor acceptor = new SocketAcceptor(executor1);
> SocketAcceptorConfig config = (SocketAcceptorConfig)
> acceptor.getDefaultConfig();
> config.setThreadModel(ThreadModel.MANUAL);
> ExecutorService executor2 = Executors.newCachedThreadPool();
> config.getFilterChain().addLast("pool", new ExecutorFilter(executor2));
>
> It's correct now? But, what the difference between these two pool? Is
> executor1 only used by I/O processor? and  executor2 work for the IoFilters
> after it in the IoFilterChain, also work for the following IoHandler?

Exactly.

> And other, you said"Adding two executor filter might not work, but please
> give it a try." Is that means adding only one thread pool into IoFilterChain
> is enough, and the other pools are redundant? en...
> http://mina.apache.org/configuring-thread-model.html
> http://mina.apache.org/configuring-thread-model.html  said that"You can add
> any number of ExecutorFilter anywhere in the IoFilterChain to implement any
> kind of thread model". What it do for me if I add multi-pools in the
> IoFilterChain?

In most cases adding only one executor filter will suffice.
Currently, more than two ExecutorFilters can't be added to a single
chain due to technical limitation.  But the limitation will be removed
in MINA 2.0.

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

Re: How could I set thread pool for IoServices and ExecutorFilters?

Posted by Messi Chan <ch...@gmail.com>.
Hi, Trustin, thx for your reply.

According to your advice, I modify those codes below:

ExecutorService executor1 = Executors.newCachedThreadPool();
SocketAcceptor acceptor = new SocketAcceptor(executor1); 
SocketAcceptorConfig config = (SocketAcceptorConfig)
acceptor.getDefaultConfig();
config.setThreadModel(ThreadModel.MANUAL);
ExecutorService executor2 = Executors.newCachedThreadPool();
config.getFilterChain().addLast("pool", new ExecutorFilter(executor2)); 

It's correct now? But, what the difference between these two pool? Is
executor1 only used by I/O processor? and  executor2 work for the IoFilters
after it in the IoFilterChain, also work for the following IoHandler? 

And other, you said"Adding two executor filter might not work, but please
give it a try." Is that means adding only one thread pool into IoFilterChain
is enough, and the other pools are redundant? en...
http://mina.apache.org/configuring-thread-model.html
http://mina.apache.org/configuring-thread-model.html  said that"You can add
any number of ExecutorFilter anywhere in the IoFilterChain to implement any
kind of thread model". What it do for me if I add multi-pools in the
IoFilterChain?

thx a lot :)


-- 
View this message in context: http://www.nabble.com/How-could-I-set-thread-pool-for-IoServices-and-ExecutorFilters--tf3882251.html#a11009495
Sent from the mina dev mailing list archive at Nabble.com.


Re: How could I set thread pool for IoServices and ExecutorFilters?

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

On 6/7/07, Messi Chan <ch...@gmail.com> wrote:
>
> Hi, all
> I have read this article
> http://mina.apache.org/configuring-thread-model.html
> http://mina.apache.org/configuring-thread-model.html . At the end of the
> article, author suggest us not share one thread pool for IoServices and
> ExecutorFilters, and better to use a cached thread pool for IoServices.
>
> Is that means if I add only one thread pool to IoFilterChain, then the  I/O
> processor would acquire a thread from the shared pool? So, adding two thread
> pools would be OK? like below.
>
> SocketAcceptorConfig config = (SocketAcceptorConfig)
> acceptor.getDefaultConfig();
> config.setThreadModel(ThreadModel.MANUAL);
> ExecutorService executor1 = Executors.newCachedThreadPool();
> config.getFilterChain().addLast("pool1", new ExecutorFilter(executor1));
> ExecutorService executor2 = Executors.newCachedThreadPool();
> config.getFilterChain().addLast("pool2", new ExecutorFilter(executor2));
>
> Am I right? if wrong, how?

Wrong.  The executor for I/O processor threads is specified in the
constructor.  For example:

SocketAcceptor acceptor = new SocketAcceptor(Executors.newCachedThreadPool());

Adding two executor filter might not work, but please give it a try.

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