Ashish wrote:
On Tue, Jun 30, 2009 at 5:13 PM, Emmanuel Lecharny<[email protected]> wrote:
Kumar Phani wrote:
I want to know how to configure the ThreadPool Executor in
Acceptor,exactly
what I need is acceptor needs to take 'n' requests simultaneoulsy.
Ok, so when you define your acceptor, you can provide a number of
IoProcessor to use, depending on the number of processor you have. The
Executor is a bit different beast : it's used if you have a long processing
part somewhere in your chain, and want to decople this part from the
processing of faster request. Not sure that you need it, it all depends on
your application.
Basically, the number of IoProcessor defaults to Nb CPU * 2 + 1. You can
change that by using the NioSocketAcceptor( int nbProcessor ) if you want to
have more processor in the pool.
I thought default size is number of processor + 1
Just trying to put in the missing pieces in my understanding
You're right :
private static final int DEFAULT_SIZE =
Runtime.getRuntime().availableProcessors() + 1;
On my dual core, DEFAULT_SIZE = 3.
You have to know that a processor is associated with a Selector, so once a
session has been registred within a IoProcessor, eveery message received or
sent on this session will be processed by this IoProcessor. If you have some
lengthly operation affecting one special message, then this IoProcessor will
wait until this processing is done before processing the next incoming or
outgoing event. However, all the other sessions associated with another
IoProcessor will be processed in parallel.
Hmm, so in a way session is sticky to an IoProcessor. Also, in this
case the messages shall be queued I guess?
Not exactly : in fact, we loop on the selectedKeys.
Last, not least, if you want an IoProcessor not to be stuck while processing
a request, just add an executor in the chain, so a pool of thread will be
used to process the messages, instead of the IoProcessor thread.
This is to obtain parallelism and if order is not important. To ensure
Order will OrderedThreadPoolExecutor be of any help?
Yep.
--
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org