You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Mark <el...@gmail.com> on 2007/10/04 14:57:56 UTC

sharing Executor between IoServices

In the Confuguring Thread Model tutorial (
http://mina.apache.org/configuring-thread-model.html), is says

"It is not recommended to share one thread pool for IoServices and
ExecutorFilters."

Is it OK to use the same executor that gets passed in to a
NioSocketAcceptor's constructor?  I think that this could help solve the
issue I entered into JIRA (https://issues.apache.org/jira/browse/DIRMINA-453
)

Thanks
-- 
..Cheers
Mark

Re: sharing Executor between IoServices

Posted by Cem Uzunlar <ce...@gmail.com>.
Hi,

1) ExecutorService es = new OrderedThreadPoolExecutor();

is this a correct thread pool for using as a global thread pool? (For
IoServices and ExecutorFilters)

2) NioSocketAcceptor acceptor = new NioSocketAcceptor(es, XXX);

What must i write as the second parameter XXX ? (processor)

3) What is the best core and maximum thread count for the
OrderedThreadPoolExecutor? (For a board game server application)

2 * Runtime.getRuntime().availableProcessors() + 1 for "IoServices +
ExecuterFilters"

is that ok?

Thanks...

--
Cem Uzunlar

2007/10/5, Trustin Lee <tr...@gmail.com>:
>
> On 10/4/07, Mark <el...@gmail.com> wrote:
> > In the Confuguring Thread Model tutorial (
> > http://mina.apache.org/configuring-thread-model.html), is says
> >
> > "It is not recommended to share one thread pool for IoServices and
> > ExecutorFilters."
> >
> > Is it OK to use the same executor that gets passed in to a
> > NioSocketAcceptor's constructor?  I think that this could help solve the
> > issue I entered into JIRA (
> https://issues.apache.org/jira/browse/DIRMINA-453
> > )
>
>
> It is OK as long as:
>
> * cached thread pool is used or
> * you counted the number of required thread correctly. :D
>
> With global worker thread pool, things will become much easier as you
> said.
>
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
>
> --
> PGP Key ID: 0x0255ECA6
>

Re: sharing Executor between IoServices

Posted by 이희승 (Trustin Lee) <t...@gmail.com>.
Hi Cem,

Cem Uzunlar wrote:
>>> 2) NioSocketAcceptor acceptor = new NioSocketAcceptor(es, XXX);
>>>
>>> What must i write as the second parameter XXX ? (processor)
> 
>> You don't need to do that.
> 
> 1) I thought that in order to use a thread pool with io services, i must use
> 
> NioSocketAcceptor acceptor = new
> NioSocketAcceptor(Executors.newCachedThreadPool(), XXX);
> 
> so, i need XXX.
> How can i use a thread pool with io services without that?

It's because the default constructor creates its own thread pool and
launches (the number of cores * 2 + 1) I/O processors automatically.

You don't need to do something special if you want to tune more.

> 2) What is the correct thread pool creation parameters for
> OrderedThreadPoolExecuter?
> corePoolSize =Runtime.getRuntime().availableProcessors() + 1
> maximumPoolSize =Runtime.getRuntime().availableProcessors() + 1
> 
> or should maximumPoolSize be higher than that?

OrderedThreadPoolExecutor and UnorderedThreadPoolExecutor are supposed
to be used with ExecutorFilter.  Therefore, the size of the pool should
depend on your business logic in your IoHandler, which means (the number
of cores * 2 + 1) is not the correct number in this case.  You need to
experiment by yourself to find out the best pool size.  Or you might
want to remove the ExecutorFilter from the filter chain in a certain case.

HTH,
-- 
Trustin Lee - Principal Software Engineer, JBoss, Red Hat
--
what we call human nature is actually human habit
--
http://gleamynode.net/


Re: sharing Executor between IoServices

Posted by Cem Uzunlar <ce...@gmail.com>.
>> 2) NioSocketAcceptor acceptor = new NioSocketAcceptor(es, XXX);
>>
>> What must i write as the second parameter XXX ? (processor)

>You don't need to do that.

1) I thought that in order to use a thread pool with io services, i must use

NioSocketAcceptor acceptor = new
NioSocketAcceptor(Executors.newCachedThreadPool(), XXX);

so, i need XXX.
How can i use a thread pool with io services without that?

2) What is the correct thread pool creation parameters for
OrderedThreadPoolExecuter?
corePoolSize =Runtime.getRuntime().availableProcessors() + 1
maximumPoolSize =Runtime.getRuntime().availableProcessors() + 1

or should maximumPoolSize be higher than that?

Thanks,

--
Cem Uzunlar


2008/3/31, 이희승 (Trustin Lee) <tr...@gmail.com>:
> Hi Cem,
>
>  Answers inline...
>
>
>  On Mon, 2008-03-31 at 06:02 +0900, Cem Uzunlar wrote:
>  > Hi,
>  >
>  > 1) ExecutorService es = new OrderedThreadPoolExecutor();
>  >
>  > is this a correct thread pool for using as a global thread pool? (For
>  > IoServices and ExecutorFilters)
>
>
> Yes for ExecutorFilters.  For IoServices, I recommed
>  Executors.newCachedThreadPool().
>
>
>  > 2) NioSocketAcceptor acceptor = new NioSocketAcceptor(es, XXX);
>  >
>  > What must i write as the second parameter XXX ? (processor)
>
>
> You don't need to do that.
>
>
>  > 3) What is the best core and maximum thread count for the
>  > OrderedThreadPoolExecutor? (For a board game server application)
>  >
>  > 2 * Runtime.getRuntime().availableProcessors() + 1 for "IoServices +
>  > ExecuterFilters"
>  >
>  > is that ok?
>
>
> Yes for IoService.  For ExecutorFilter, you will have to experiment.
>  You can even try to drop ExecutorFilter from your filter chain depending
>  on what your application is going to do.
>
>  HTH,
>
>
>  --
>  Trustin Lee - Principal Software Engineer, JBoss, Red Hat
>
> --
>  what we call human nature is actually human habit
>  --
>  http://gleamynode.net/
>
>

Re: sharing Executor between IoServices

Posted by "이희승 (Trustin Lee)" <tr...@gmail.com>.
Hi Cem,

Answers inline...

On Mon, 2008-03-31 at 06:02 +0900, Cem Uzunlar wrote:
> Hi,
> 
> 1) ExecutorService es = new OrderedThreadPoolExecutor();
> 
> is this a correct thread pool for using as a global thread pool? (For
> IoServices and ExecutorFilters)

Yes for ExecutorFilters.  For IoServices, I recommed
Executors.newCachedThreadPool().

> 2) NioSocketAcceptor acceptor = new NioSocketAcceptor(es, XXX);
> 
> What must i write as the second parameter XXX ? (processor)

You don't need to do that.

> 3) What is the best core and maximum thread count for the
> OrderedThreadPoolExecutor? (For a board game server application)
> 
> 2 * Runtime.getRuntime().availableProcessors() + 1 for "IoServices +
> ExecuterFilters"
> 
> is that ok?

Yes for IoService.  For ExecutorFilter, you will have to experiment.
You can even try to drop ExecutorFilter from your filter chain depending
on what your application is going to do.

HTH,

-- 
Trustin Lee - Principal Software Engineer, JBoss, Red Hat
--
what we call human nature is actually human habit
--
http://gleamynode.net/

Re: sharing Executor between IoServices

Posted by Cem Uzunlar <ce...@gmail.com>.
Hi,

1) ExecutorService es = new OrderedThreadPoolExecutor();

is this a correct thread pool for using as a global thread pool? (For
IoServices and ExecutorFilters)

2) NioSocketAcceptor acceptor = new NioSocketAcceptor(es, XXX);

What must i write as the second parameter XXX ? (processor)

3) What is the best core and maximum thread count for the
OrderedThreadPoolExecutor? (For a board game server application)

2 * Runtime.getRuntime().availableProcessors() + 1 for "IoServices +
ExecuterFilters"

is that ok?

Thanks...

--
Cem Uzunlar


2007/10/5, Trustin Lee <tr...@gmail.com>:
> On 10/4/07, Mark <el...@gmail.com> wrote:
>  > In the Confuguring Thread Model tutorial (
>  > http://mina.apache.org/configuring-thread-model.html), is says
>  >
>  > "It is not recommended to share one thread pool for IoServices and
>  > ExecutorFilters."
>  >
>  > Is it OK to use the same executor that gets passed in to a
>  > NioSocketAcceptor's constructor?  I think that this could help solve the
>  > issue I entered into JIRA (https://issues.apache.org/jira/browse/DIRMINA-453
>  > )
>
>
> It is OK as long as:
>
>  * cached thread pool is used or
>  * you counted the number of required thread correctly. :D
>
>  With global worker thread pool, things will become much easier as you said.
>
>  Trustin
>  --
>  what we call human nature is actually human habit
>  --
>  http://gleamynode.net/
>
> --
>  PGP Key ID: 0x0255ECA6
>

Re: sharing Executor between IoServices

Posted by Trustin Lee <tr...@gmail.com>.
On 10/4/07, Mark <el...@gmail.com> wrote:
> In the Confuguring Thread Model tutorial (
> http://mina.apache.org/configuring-thread-model.html), is says
>
> "It is not recommended to share one thread pool for IoServices and
> ExecutorFilters."
>
> Is it OK to use the same executor that gets passed in to a
> NioSocketAcceptor's constructor?  I think that this could help solve the
> issue I entered into JIRA (https://issues.apache.org/jira/browse/DIRMINA-453
> )

It is OK as long as:

* cached thread pool is used or
* you counted the number of required thread correctly. :D

With global worker thread pool, things will become much easier as you said.

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