When is ExecutionHandler necessary

Trustin Lee (이희승) trustin at gmail.com
Wed Oct 21 21:26:54 EDT 2009


Hi Dan,

Frederic already answered pretty enough, but I want to add just one more thing.

ChannelFactory consumes only a fixed number of threads from the the
thread pool that was specified in the constructor.  No extra threads
are pulled from the thread pool even if you run a long running task in
your handler (how would you define a 'long running task' and run the
task in a new thread automatically?).  Therefore, you have to either
add ExecutionHandler or use your own thread pool to submit a task to
the thread pool.  Otherwise, the long running task will block the I/O
of other channels, decreasing the overall performance of the
networking layer.

HTH

— Trustin Lee, http://gleamynode.net/



On Mon, Oct 19, 2009 at 4:59 PM, Frederic Bregier <fredbregier at free.fr> wrote:
>
> Hi Dan,
>
> There is two solutions there.
>
> Either you use an ExecutionHandler in the pipeline since long-running
> business task needs to be submitted to another thread pool than I/O thread
> (or you will decrease your performance).
>
> Either you internaly submit your job in the handler to your own ThreadPool,
> but then you have to take care of the order of new runners (two submission
> can execute at the same time from two messages that arrived in order but as
> the execution is long, the two threads can overlap each other). Also you
> shouldn't wait for anything in the handler from the new sumbitted task since
> if you do (waiting on a condition), then your submission is like direct
> running and your I/O thread will wait for the end of execution as if you
> don't used a thread pool. If this is correct from your business point of
> view (sumbitted task without waiting anything in the handler and allowing
> overlapping of execution of submitted task - or at least have a control on
> it - ), then it is correct.
>
> Generally, OrderedMemoryAwareThreadPoolExecutor does the stuff as needed and
> is simpler to implement.
>
> HTH,
> Cheers,
> Frederic
>
>
> Dan D wrote:
>>
>> Thanks Frederic.  I'm still not clear on whether I can just avoid using
>> ExecutionHandler, run long-running business logic directly in the Netty
>> I/O
>> threads, and rely on using a CachedThreadPool for the Netty I/O threads
>> to
>> ensure that there's going to be available threads for Netty to do its
>> thing.
>>
>> Also, I was wondering whether there was any problem in submitting a task
>> to
>> my own threadpool from my own handler rather using any ExecutionHandler at
>> all (without caring about event ordering or anything like that).
>>
>>
>> Date: Sun, 18 Oct 2009 00:24:04 -0700 (PDT)
>>> From: Frederic Bregier <fredbregier at free.fr>
>>> Subject: Re: When is ExecutionHandler necessary
>>> To: netty-users at lists.jboss.org
>>> Message-ID: <1255850644557-3843469.post at n2.nabble.com>
>>> Content-Type: text/plain; charset=us-ascii
>>>
>>>
>>> Hi Dan,
>>>
>>> Take a look at the documentation and specifically the API.
>>> One advantage of the given ExecutionHandler (specifically
>>> OrderedMemoryAwareThreadPoolExecutor) is that message will be kept in
>>> order
>>> for one channel. If you don't have any such need (message can arrived in
>>> any
>>> order for any channel), then my believe is that you can use your own
>>> ExecutionHandler.
>>>
>>> Cheers,
>>> Frederic
>>>
>>>
>>> Dan D wrote:
>>> >
>>> > bump
>>> >
>>> > On Thu, Oct 15, 2009 at 11:10 AM, Dan D <danotsky at gmail.com> wrote:
>>> >
>>> >> Below, Trustin mentions using an ExecutionHandler for long-running
>>> >> business
>>> >> logic to prevent tying up Netty's worker threadpool.  If a cached
>>> thread
>>> >> pool is being used for the worker threads, is this still a problem?
>>> >> Won't
>>> >> the threadpool just expand as necessary if business logic is tying up
>>> >> threads?
>>> >>
>>> >> Also is an ExecutionHandler required, or can we just submit work to
>>> our
>>> >> own
>>> >> ExecutorService?  If ExecutionHandler isn't required, what are the
>>> >> benefits
>>> >> to using one?
>>> >>
>>> >> Thanks.
>>> >>
>>> >>
>>> >>
>>> >>> On Tue, Sep 29, 2009 at 3:42 AM, Trustin Lee (???)
>>> <trustin at gmail.com>
>>> >>> wrote:
>>> >>> > Hi Wade,
>>> >>> >
>>> >>> > If your business logic takes long time, then you should use an
>>> >>> > ExecutionHandler. ?Otherwise, other connections will freeze until
>>> the
>>> >>> > long operation finishes. ?If there's no long operation in your
>>> >>> > business logic, you don't usually need an ExecutionHandler in your
>>> >>> > pipeline.
>>> >>> >
>>> >>> > I also suggest to put decoders and encoders before ExecutionHandler
>>> >>> > (if there is one), because decoders and encoders usually do
>>> CPU-bound
>>> >>> > jobs.
>>> >>> >
>>> >>> > HTH,
>>> >>> >
>>> >>> > ? Trustin Lee, http://gleamynode.net/
>>> >>> >
>>> >>>
>>> >>
>>> >
>>> > _______________________________________________
>>> > netty-users mailing list
>>> > netty-users at lists.jboss.org
>>> > https://lists.jboss.org/mailman/listinfo/netty-users
>>> >
>>> >
>>>
>>>
>>> -----
>>> Hardware/Software Architect
>>> --
>>> View this message in context:
>>> http://n2.nabble.com/When-is-ExecutionHandler-necessary-tp3831101p3843469.html
>>> Sent from the Netty User Group mailing list archive at Nabble.com.
>>>
>>>
>>>
>>
>> _______________________________________________
>> netty-users mailing list
>> netty-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/netty-users
>>
>>
>
>
> -----
> Hardware/Software Architect
> --
> View this message in context: http://n2.nabble.com/When-is-ExecutionHandler-necessary-tp3831101p3847703.html
> Sent from the Netty User Group mailing list archive at Nabble.com.
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>



More information about the netty-users mailing list