You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Frederic Soulier <fr...@wallaby.uklinux.net> on 2006/11/07 12:43:01 UTC
Re: [Mina 1.0] Question concerning SocketAcceptor creation and
executors on a dual-processor server
On Tue, 2006-11-07 at 10:48 +0100, Sven Panko wrote:
> For SocketAcceptor (or IoAcceptor) :
> Executor executor1 = Executors.newFixedThreadPool(nbThread);
> SocketAcceptor acceptor = new SocketAcceptor(nbThread, executor1);
>
> My feeling is that it shouldn't be a newCachedThreadPool here since
> it seems it is relative to the number of SocketIoProcessors that
> the SocketAcceptor will use.
> By default (new SocketAcceptor() without arguments), it use
> a value of 16 threads and SocketIoProcessors.
> --- end quote
>
> What I do not understand is: why do I have to specify two numbers of
> threads (one during the specification of the fixed thread pool and one
> when constructing the socket acceptor)? Frederic sets both times an
> identical value, but how are they related? Or is the first argument in the
> SocketAcceptor constructor just an information how many (core) threads the
> executor will use?
Hi sven
I believe the default behaviour in MINA 1.0.0 is 1 SocketIoProcessor
with a cached thread pool.
Specifying a number of threads in:
SocketAcceptor acceptor = new SocketAcceptor(nbThread, executor1);
will dictate how many SocketIoProcessor(s) you want.
A good start is 1 for single-cpu, 2 for dual-cpus (or dual core), etc...
Basically 1 SocketIoProcessor per CPU although at some stage you need to
run performance tests to adapt your app to your hardware and see what's
best.
Specifying a number of threads in:
Executor executor1 = Executors.newFixedThreadPool(nbThread);
will dictate how many threads are in the thread pool.
Bear in mind the number of threads is fixed so if you have many clients
connecting you may have issues here.
To reproduce MINA's 1.0.0 default behaviour you need to use :
Executor executor1 = Executors.newCachedThreadPool();
because then the pool can grow if necessary.
I recommend you have a look at the Javadoc of the Java Concurrent Util
backport.
Example:
Executor executor1 = Executors.newFixedThreadPool(10);
SocketAcceptor acceptor = new SocketAcceptor(2, executor1);
will setup 2 SocketIoProcessors sharing a thread pool of 10 threads.
If you have more than 10 clients connecting and sending/receiving at the
same time you may have pbms hence why depending on the intent of your
app it may be better to use:
Executor executor1 = Executors.newCachedThreadPool();
SocketAcceptor acceptor = new SocketAcceptor(2, executor1);
in order to allow the pool to grow if need be.
So to answer your question the two "nbThreads" value are not related.
Pls anyone on the list correct me if I'm wrong.
--
Frederic Soulier <fr...@wallaby.uklinux.net>
OpenPGP key available on http://www.keyserver.net
1024D/BA6700ED 49A6 8E8E 4230 8D41 1ADE B649 3203 1DD2 BA67 00ED
Re: [Mina 1.0] Question concerning SocketAcceptor creation and executors on a dual-processor server
Posted by peter royal <pr...@apache.org>.
On Nov 7, 2006, at 10:14 AM, Sven Panko wrote:
> After Peters remark I am still puzzled: is it better to rely on
> SocketAcceptor's default constructor (and do not specify executors/
> socket
> io processors at all) or can I go with this for the dual processor
> machine?
>
> --- snip start
> Executor executor = Executors.newCachedThreadPool();
> SocketAcceptor acceptor = new SocketAcceptor(2, executor);
> --- snip end
>
> --- quote start
> The above example will only use 3 threads from the pool.
> 1 for accepting, and 2 for the processing of existing connection.
> --- quote end
>
> And - just out of curiosity - why does MINA use exactly 3 threads
> when I
> use this construct?
>
> --- snip start
> Executor executor1 = Executors.newFixedThreadPool(10);
> SocketAcceptor acceptor = new SocketAcceptor(2, executor1);
> --- snip end
the SocketAcceptor is going to use a certain number of threads, based
on the first parameter.
The Executor is just there for it to get the threads its going to
use. You could use a 'NewThreadExecutor()' if you don't want to worry
about pool sizing. Its an Executor implementation that just launches
a new thread.
-pete
--
proyal@apache.org - http://fotap.org/~osi
Re: [Mina 1.0] Question concerning SocketAcceptor creation and executors on
a dual-processor server
Posted by Sven Panko <Sv...@proximity.de>.
First of all, Frederic and Peter, thanks for your detailed explanation!
After Peters remark I am still puzzled: is it better to rely on
SocketAcceptor's default constructor (and do not specify executors/socket
io processors at all) or can I go with this for the dual processor
machine?
--- snip start
Executor executor = Executors.newCachedThreadPool();
SocketAcceptor acceptor = new SocketAcceptor(2, executor);
--- snip end
--- quote start
The above example will only use 3 threads from the pool.
1 for accepting, and 2 for the processing of existing connection.
--- quote end
And - just out of curiosity - why does MINA use exactly 3 threads when I
use this construct?
--- snip start
Executor executor1 = Executors.newFixedThreadPool(10);
SocketAcceptor acceptor = new SocketAcceptor(2, executor1);
--- snip end
Sven
peter royal <pr...@apache.org> wrote on 07.11.2006 16:54:53:
> On Nov 7, 2006, at 3:43 AM, Frederic Soulier wrote:
> > Example:
> > Executor executor1 = Executors.newFixedThreadPool(10);
> > SocketAcceptor acceptor = new SocketAcceptor(2, executor1);
> > will setup 2 SocketIoProcessors sharing a thread pool of 10 threads.
> > If you have more than 10 clients connecting and sending/receiving
> > at the
> > same time you may have pbms hence why depending on the intent of your
> > app it may be better to use:
>
> actually, not exactly..
>
> the Executor parameter to the SocketAcceptor merely provides a source
> for threads. The above example will only use 3 threads from the pool.
> 1 for accepting, and 2 for the processing of existing connection.
> (The constructor that takes an Executor was added for people that are
> integrating MINA into larger systems that want to centralize thread
> creation for the entire application)
>
> I think you may be thinking of the ExecutorFilter, which does bring
> the performance implications you mention.
>
> -pete
>
>
> --
> proyal@apache.org - http://fotap.org/~osi
>
>
>
Information contained in this message is confidential and may be legally privileged. If you are not the addressee indicated in this message (or responsible for the delivery of the message to such person), you may not copy, disclose or deliver this message or any part of it to anyone, in any form. In such case, you should delete this message and kindly notify the sender by reply Email. Opinions, conclusions and other information in this message that do not relate to the official business of Proximity shall be understood as neither given nor endorsed by it.
Re: [Mina 1.0] Question concerning SocketAcceptor creation and executors on a dual-processor server
Posted by peter royal <pr...@apache.org>.
On Nov 7, 2006, at 3:43 AM, Frederic Soulier wrote:
> Example:
> Executor executor1 = Executors.newFixedThreadPool(10);
> SocketAcceptor acceptor = new SocketAcceptor(2, executor1);
> will setup 2 SocketIoProcessors sharing a thread pool of 10 threads.
> If you have more than 10 clients connecting and sending/receiving
> at the
> same time you may have pbms hence why depending on the intent of your
> app it may be better to use:
actually, not exactly..
the Executor parameter to the SocketAcceptor merely provides a source
for threads. The above example will only use 3 threads from the pool.
1 for accepting, and 2 for the processing of existing connection.
(The constructor that takes an Executor was added for people that are
integrating MINA into larger systems that want to centralize thread
creation for the entire application)
I think you may be thinking of the ExecutorFilter, which does bring
the performance implications you mention.
-pete
--
proyal@apache.org - http://fotap.org/~osi