You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Greg Duffy <gd...@gmail.com> on 2006/03/23 07:58:50 UTC

IoConnectors and Thread Pools

Could someone outline the process for setting up an IoConnector
(DatagramConnector specifically) to use a Thread Pool?

It seems like no matter what I do, my protocol encoder always executes
in the IoConnector's thread. I've tried adding a ThreadPoolFilter
manually in the IoConnectorConfig and in the IoHandler when an
IoSession is created. I've also tried removing my ThreadPoolFilter and
using the new default ThreadModel, PooledThreadModel.

Could someone write a short example of how to accomplish this? I
looked into the code a bit, and noticed that the ThreadPoolFilter
doesn't spawn a thread for filterWrite ... is that the problem, or is
that the way it was intended to be?

Thanks
-Greg

Re: IoConnectors and Thread Pools

Posted by Greg Duffy <gd...@gmail.com>.
Also, I am running the latest trunk as you suggested.

On 3/23/06, Greg Duffy <gd...@gmail.com> wrote:
> Trustin,
>
> I did see that messageSent was being executed in a thread from the
> thread pool. I guess my question is: what is the best way to write a
> multi-threaded client? It seems like things like the protocol encoder
> (which catches filterWrite, I guess) should run in a pooled thread.
>
> Is it up to me to make sure that happens by executing session.write()
> in my own external thread pool? If so, what is the use of a thread
> pool in the IoConnector case, what operations is it speeding up (if
> not the protocol encoder)?
>
> Thanks for your help, Trustin.
>
> -Greg
>
> On 3/23/06, Trustin Lee <tr...@gmail.com> wrote:
> > On 3/23/06, Greg Duffy <gd...@gmail.com> wrote:
> > >
> > > Could someone outline the process for setting up an IoConnector
> > > (DatagramConnector specifically) to use a Thread Pool?
> > >
> > > It seems like no matter what I do, my protocol encoder always executes
> > > in the IoConnector's thread. I've tried adding a ThreadPoolFilter
> > > manually in the IoConnectorConfig and in the IoHandler when an
> > > IoSession is created. I've also tried removing my ThreadPoolFilter and
> > > using the new default ThreadModel, PooledThreadModel.
> >
> >
> > I ran the NetCat example in a debug mode and it works as I expected; a
> > thread pool is launched.
> >
> > Please try to build MINA from Subversion repository.
> >
> > HTH,
> > Trustin
> > --
> > what we call human nature is actually human habit
> > --
> > http://gleamynode.net/
> > --
> > PGP key fingerprints:
> > * E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
> > * B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6
> >
> >
>

Re: IoConnectors and Thread Pools

Posted by Trustin Lee <tr...@gmail.com>.
On 3/24/06, Greg Duffy <gd...@gmail.com> wrote:
>
> Trustin,
>
> I did see that messageSent was being executed in a thread from the
> thread pool. I guess my question is: what is the best way to write a
> multi-threaded client? It seems like things like the protocol encoder
> (which catches filterWrite, I guess) should run in a pooled thread.


Yes, you're right.  Robert says that he modified the ThreadPoolFilter so
IoSession.write() also runs in a thread pool thread.  Let's wait for him for
a while.

Is it up to me to make sure that happens by executing session.write()
> in my own external thread pool? If so, what is the use of a thread
> pool in the IoConnector case, what operations is it speeding up (if
> not the protocol encoder)?


All events are still executed in a thread pool thread, and therefore, your
IoHandler implementation gets benefits from it.  For example, you can write
your messages in sessionOpened() method.

HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6

Re: IoConnectors and Thread Pools

Posted by Greg Duffy <gd...@gmail.com>.
Trustin,

I did see that messageSent was being executed in a thread from the
thread pool. I guess my question is: what is the best way to write a
multi-threaded client? It seems like things like the protocol encoder
(which catches filterWrite, I guess) should run in a pooled thread.

Is it up to me to make sure that happens by executing session.write()
in my own external thread pool? If so, what is the use of a thread
pool in the IoConnector case, what operations is it speeding up (if
not the protocol encoder)?

Thanks for your help, Trustin.

-Greg

On 3/23/06, Trustin Lee <tr...@gmail.com> wrote:
> On 3/23/06, Greg Duffy <gd...@gmail.com> wrote:
> >
> > Could someone outline the process for setting up an IoConnector
> > (DatagramConnector specifically) to use a Thread Pool?
> >
> > It seems like no matter what I do, my protocol encoder always executes
> > in the IoConnector's thread. I've tried adding a ThreadPoolFilter
> > manually in the IoConnectorConfig and in the IoHandler when an
> > IoSession is created. I've also tried removing my ThreadPoolFilter and
> > using the new default ThreadModel, PooledThreadModel.
>
>
> I ran the NetCat example in a debug mode and it works as I expected; a
> thread pool is launched.
>
> Please try to build MINA from Subversion repository.
>
> HTH,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP key fingerprints:
> * E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
> * B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6
>
>

Re: IoConnectors and Thread Pools

Posted by Trustin Lee <tr...@gmail.com>.
On 3/23/06, Greg Duffy <gd...@gmail.com> wrote:
>
> Could someone outline the process for setting up an IoConnector
> (DatagramConnector specifically) to use a Thread Pool?
>
> It seems like no matter what I do, my protocol encoder always executes
> in the IoConnector's thread. I've tried adding a ThreadPoolFilter
> manually in the IoConnectorConfig and in the IoHandler when an
> IoSession is created. I've also tried removing my ThreadPoolFilter and
> using the new default ThreadModel, PooledThreadModel.


I ran the NetCat example in a debug mode and it works as I expected; a
thread pool is launched.

Please try to build MINA from Subversion repository.

HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6

Re: IoConnectors and Thread Pools

Posted by Trustin Lee <tr...@gmail.com>.
On 3/23/06, Greg Duffy <gd...@gmail.com> wrote:
>
> Could someone outline the process for setting up an IoConnector
> (DatagramConnector specifically) to use a Thread Pool?
>
> It seems like no matter what I do, my protocol encoder always executes
> in the IoConnector's thread. I've tried adding a ThreadPoolFilter
> manually in the IoConnectorConfig and in the IoHandler when an
> IoSession is created. I've also tried removing my ThreadPoolFilter and
> using the new default ThreadModel, PooledThreadModel.
>
> Could someone write a short example of how to accomplish this? I
> looked into the code a bit, and noticed that the ThreadPoolFilter
> doesn't spawn a thread for filterWrite ... is that the problem, or is
> that the way it was intended to be?


session.write() doesn't run in a thread pool.  It is executed in the current
thread you called write().

Did you check if event handler methods run in a thread pool?

HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6