You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Murat OZDEMiR <mo...@gmail.com> on 2007/04/11 11:28:46 UTC

setting IoProcessor thread number and SocketAcceptor threads

Question - 1
I'm trying to set IoProcessor thread number. 
 
At http://mina.apache.org/configuring-thread-model.html under Configure the
number of I/O worker threads title a sample code is given to determine the
I/O Processor thread as 
 
IoAcceptor acceptor = new
SocketAcceptor(Runtime.getRuntime().availableProcessors() + 1,
Executors.newCachedThreadPool());
// SocketAcceptor is constructed with int as arg[0] and ExecuterServie as
arg[1]
 
But "The constructer SocketAcceptor ( int, ExecuterService ) is undefined"
error occurs, 
 
i took a loot into the source code for SocketAcceptor.class and faced that
 
    public SocketAcceptor()
    {
        this( 1, new NewThreadExecutor() );
    }
 
 
    public SocketAcceptor( int processorCount, Executor executor )
    {
        ...
    }
 
So, faced no constructer like SocketAcceptor ( int processorCount,
ExecuterService executerService). 
 
this code is working;
gprsHandlerTcpAcceptor = new SocketAcceptor(
Runtime.getRuntime().availableProcessors() + 1, new NewThreadExecutor() );
 
How can i use Executors.newCachedThreadPool() as a parameter? And what is
the difference between my code and sample?
 
Question - 2
i've build a Tcp Socket Acceptor as
gprsHandlerTcpConfig.setThreadModel(
ExecutorThreadModel.getInstance("GprsTcpSocketAcceptor"));
 
and max. 16 threads is built when new messages are received or connections
are accepted.
[GprsTcpSocketAcceptor-1]
...
[GprsTcpSocketAcceptor-16]
 
How can i change the number of SocketAcceptor threads?
And also DatagramAcceptor and SocketConnector?
 
Saygılarımla...
 
Murat ÖZDEMİR
Yazılım Tasarım Mühendisi


Tel
:
0 312 265 00 60

Faks
:
0 312 265 00 63

Web
:
http://www.mobiliz.com.tr <http://www.mobiliz.com.tr/> 

Email
:
murato@mobiliz.com.tr

 

Re: setting IoProcessor thread number and SocketAcceptor threads

Posted by Trustin Lee <tr...@gmail.com>.
On 4/11/07, Murat OZDEMiR <mo...@gmail.com> wrote:
>
> Hi Trustin,
>
> ...
> Executors.newCachedThreadPool:
> Creates a thread pool that creates new threads as needed, but will reuse
> previously constructed threads when they are available, and uses the
> provided ThreadFactory to create new threads when needed.
> ...
>
> Are the two of code parts given below same?
>
> 1)
> gprsHandlerTcpAcceptor = new SocketAcceptor(
> Runtime.getRuntime().availableProcessors() + 1,
> Executors.newCachedThreadPool() );
>
> 2)
> gprsHandlerTcpChainBuilder.addLast(
>                 "gprsHandlerTcpAcceptorThreadPool",
>                 new ExecutorFilter( Executors.newCachedThreadPool() ) );
>
> If yes i guess using Executors.newCachedThreadPool() in SocketAcceptor
> constructer more logical. Isn't it?
> Anything that i have full control for that executor ?

No, they aren't.  As specified in the tutorial, they are different threads.

I suspect you didn't read the tutorial carefully.  If you are having
any difficulty understanding the tutorial, please let us know where
exactly you don't understand.  Please note people won't answer your
questions if you didn't RTFM!

> Despite i'm using 2 cores processor and
> "Runtime.getRuntime().availableProcessors() + 1" parameter in SocketAcceptor
> constructer, only one SocketAcceptorIoProcessor-0.0 Thread is running. Do
> you say why?

You might not have enough number of connected sessions.  The I/O
processor thread starts on demand.  Try to make more simultaneous
connections.

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

RE: setting IoProcessor thread number and SocketAcceptor threads

Posted by Murat OZDEMiR <mo...@gmail.com>.
 
Hi Trustin,

...
Executors.newCachedThreadPool:
Creates a thread pool that creates new threads as needed, but will reuse
previously constructed threads when they are available, and uses the
provided ThreadFactory to create new threads when needed. 
...

Are the two of code parts given below same?

1) 
gprsHandlerTcpAcceptor = new SocketAcceptor(
Runtime.getRuntime().availableProcessors() + 1,
Executors.newCachedThreadPool() );

2)
gprsHandlerTcpChainBuilder.addLast(
		"gprsHandlerTcpAcceptorThreadPool", 
		new ExecutorFilter( Executors.newCachedThreadPool() ) );

If yes i guess using Executors.newCachedThreadPool() in SocketAcceptor
constructer more logical. Isn't it?
Anything that i have full control for that executor ?

Despite i'm using 2 cores processor and
"Runtime.getRuntime().availableProcessors() + 1" parameter in SocketAcceptor
constructer, only one SocketAcceptorIoProcessor-0.0 Thread is running. Do
you say why?

Thanks.
----------
Murat OZDEMiR

-----Original Message-----
From: Trustin Lee [mailto:trustin@gmail.com] 
Sent: Wednesday, April 11, 2007 2:16 PM
To: dev@mina.apache.org
Subject: Re: setting IoProcessor thread number and SocketAcceptor threads

On 4/11/07, Murat OZDEMiR <mo...@gmail.com> wrote:

<snip/>

> Question - 2
> Pls. correct me if i'm wrong, if i don't use Thread Model an 
> AnonymousIoService thread pool (1-16) is running. If i use it, 
> different Thread pools are constructed for me. Do you say not to use 
> Thread Model because of performance loss? Are all these threads 
> constructed for each I/O session or constructed once? How can i change 
> the number of threads for thread pool? I guess you've many many times 
> explained that subject to the other developers but before i asked you, 
> i've looked javadocs, examples, bla bla bla. But i still have 
> unanswered questions in my mind :) Thanks for your understanding

ThreadModel causes confusion.  That's why I suggested to disable ThreadModel
from the beginning of the tutorial.

To create a thread pool that satisfies your needs, Please refer to Executors
class.  Once an Executor is created, you can specify the Executor as a
constructor argument of ExecutorFilter.  Insert the newly created
ExecutorFilter to your filter chain.  Once again, you have full control for
what executor you will use.

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


Re: setting IoProcessor thread number and SocketAcceptor threads

Posted by Trustin Lee <tr...@gmail.com>.
On 4/11/07, Murat OZDEMiR <mo...@gmail.com> wrote:

<snip/>

> Question - 2
> Pls. correct me if i'm wrong, if i don't use Thread Model an
> AnonymousIoService thread pool (1-16) is running. If i use it, different
> Thread pools are constructed for me. Do you say not to use Thread Model
> because of performance loss? Are all these threads constructed for each I/O
> session or constructed once? How can i change the number of threads for
> thread pool? I guess you've many many times explained that subject to the
> other developers but before i asked you, i've looked javadocs, examples, bla
> bla bla. But i still have unanswered questions in my mind :) Thanks for your
> understanding

ThreadModel causes confusion.  That's why I suggested to disable
ThreadModel from the beginning of the tutorial.

To create a thread pool that satisfies your needs, Please refer to
Executors class.  Once an Executor is created, you can specify the
Executor as a constructor argument of ExecutorFilter.  Insert the
newly created ExecutorFilter to your filter chain.  Once again, you
have full control for what executor you will use.

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

RE: setting IoProcessor thread number and SocketAcceptor threads

Posted by Murat OZDEMiR <mo...@gmail.com>.
Hi Trustin,
Thank you for your reply. I'm a little bit confused while reading Thread
Model Tutorial. I'm trying to understand which is more effective; to use
Thread Model or not.

Question - 1 is ok. After importing
"edu.emory.mathcs.backport.java.util.concurrent.Executors" instead of
"java.util.concurrent.Executors" error is removed.

Question - 2
Pls. correct me if i'm wrong, if i don't use Thread Model an
AnonymousIoService thread pool (1-16) is running. If i use it, different
Thread pools are constructed for me. Do you say not to use Thread Model
because of performance loss? Are all these threads constructed for each I/O
session or constructed once? How can i change the number of threads for
thread pool? I guess you've many many times explained that subject to the
other developers but before i asked you, i've looked javadocs, examples, bla
bla bla. But i still have unanswered questions in my mind :) Thanks for your
understanding

----------
Murat OZDEMiR

-----Original Message-----
From: Trustin Lee [mailto:trustin@gmail.com] 
Sent: Wednesday, April 11, 2007 12:34 PM
To: dev@mina.apache.org
Subject: Re: setting IoProcessor thread number and SocketAcceptor threads

Hi Murat,

On 4/11/07, Murat OZDEMiR <mo...@gmail.com> wrote:
>
>  *Question - 1*
> I'm trying to set IoProcessor thread number.
>
> At http://mina.apache.org/configuring-thread-model.html under 
> *Configure the number of I/O worker threads* title a sample code is 
> given to determine the I/O Processor thread as
>
> IoAcceptor acceptor = new 
> SocketAcceptor(Runtime.getRuntime().availableProcessors()
> + 1, Executors.newCachedThreadPool());
> // SocketAcceptor is constructed with int as arg[0] and ExecuterServie 
> as arg[1]
>
> But "*The constructer SocketAcceptor ( int, ExecuterService ) is 
> undefined *" error occurs,
>
> i took a loot into the source code for SocketAcceptor.class and faced 
> that
>
>     public SocketAcceptor()
>     {
>         this( 1, new NewThreadExecutor() );
>     }
>
>
>     public SocketAcceptor( int processorCount, Executor executor )
>     {
>         ...
>     }
>
> So, faced no constructer like SocketAcceptor ( int processorCount, 
> ExecuterService executerService).
>
> this code is working;
> gprsHandlerTcpAcceptor = new SocketAcceptor( 
> Runtime.getRuntime().availableProcessors()
> + 1, new NewThreadExecutor() );
>
> How can i use Executors.newCachedThreadPool() as a parameter? And what 
> is the difference between my code and sample?
>

ExecutorService extends Executor.  Please try before you ask.

*Question - 2*
> i've build a Tcp Socket Acceptor as
> gprsHandlerTcpConfig.setThreadModel( ExecutorThreadModel.getInstance 
> ("GprsTcpSocketAcceptor"));
>
> and max. 16 threads is built when new messages are received or 
> connections are accepted.
> [GprsTcpSocketAcceptor-1]
> ...
>  [GprsTcpSocketAcceptor-16]
>
> How can i change the number of SocketAcceptor threads?
> And also DatagramAcceptor and SocketConnector?
>

Please don't use ThreadModel, and follow the instruction in the tutorial.
Are you sure you read it?

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


Re: setting IoProcessor thread number and SocketAcceptor threads

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

On 4/11/07, Murat OZDEMiR <mo...@gmail.com> wrote:
>
>  *Question - 1*
> I'm trying to set IoProcessor thread number.
>
> At http://mina.apache.org/configuring-thread-model.html under *Configure
> the number of I/O worker threads* title a sample code is given to
> determine the I/O Processor thread as
>
> IoAcceptor acceptor = new SocketAcceptor(Runtime.getRuntime().availableProcessors()
> + 1, Executors.newCachedThreadPool());
> // SocketAcceptor is constructed with int as arg[0] and ExecuterServie as
> arg[1]
>
> But "*The constructer SocketAcceptor ( int, ExecuterService ) is undefined
> *" error occurs,
>
> i took a loot into the source code for SocketAcceptor.class and faced that
>
>     public SocketAcceptor()
>     {
>         this( 1, new NewThreadExecutor() );
>     }
>
>
>     public SocketAcceptor( int processorCount, Executor executor )
>     {
>         ...
>     }
>
> So, faced no constructer like SocketAcceptor ( int processorCount,
> ExecuterService executerService).
>
> this code is working;
> gprsHandlerTcpAcceptor = new SocketAcceptor( Runtime.getRuntime().availableProcessors()
> + 1, new NewThreadExecutor() );
>
> How can i use Executors.newCachedThreadPool() as a parameter? And what is
> the difference between my code and sample?
>

ExecutorService extends Executor.  Please try before you ask.

*Question - 2*
> i've build a Tcp Socket Acceptor as
> gprsHandlerTcpConfig.setThreadModel( ExecutorThreadModel.getInstance
> ("GprsTcpSocketAcceptor"));
>
> and max. 16 threads is built when new messages are received or connections
> are accepted.
> [GprsTcpSocketAcceptor-1]
> ...
>  [GprsTcpSocketAcceptor-16]
>
> How can i change the number of SocketAcceptor threads?
> And also DatagramAcceptor and SocketConnector?
>

Please don't use ThreadModel, and follow the instruction in the tutorial.
Are you sure you read it?

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