server ExecutionHandler question

Trustin Lee trustin at gleamynode.net
Mon Jan 26 08:24:37 EST 2009


Hi miarkus,

On Mon, Jan 26, 2009 at 6:48 AM, miarkus <miarkus at tlen.pl> wrote:
> Since I consider myself as java newbie I do have some questions about
> ExecutionHandler on server side. Business logic handler of my server
> connects to mysql making few queries so I'm assigning
> OrderedMemoryAwareThreadPoolExecutor to prevent blocking business action
> true?

True :-)

> 1) I assume that each channelhandler which queries mysql will use such
> executor right?

To be more precise, all ChannelHandlers that are placed after the
ExecutionHandler will use the Executor.  So, yes, they will.

> 2) Some channelhandlers won't be querying mysql - does this mean that they
> won't be using executors thread pools?

No.  Neither Executor nor ExecutionHandler has no idea what you are
going to do in your ChannelHandler.  All events will be executed by
the Executor (again only true for the handlers placed after the
ExecutionHandler).  If you want a certain event not to be executed by
the Executor, then you can override ExecutionHandler.handleUpstream()
so that the event is not forwarded to the Executor:

    public void handleUpstream(ctx, evt) {
        if (evt is something special) {
            ctx.sendUpstream(evt);
        } else {
            super.handleUpstream(ctx, evt) {
        }
    }

> 3) Let's say I'm setting OrderedMemoryAwareThreadPoolExecutor's corePoolSize
> to 16. If concurrently let's say 20 channelhandlers would like to query
> mysql - will 4 operations be waiting in queue to be performed in executors
> threadpool until those 16 will be completed?

Yes, if the 16 queries were triggered by different connections.
Otherwise, more than 4 queries can be waiting.  It's because
OrderedMemoryAwareThreadPoolExecutor is designed to make sure more
than one event for the same Channel are not executed concurrently.  If
you want higher concurrency at the risk of incorrect event order, you
can use MemoryAwareThreadPoolExecutor (note that there's no
'Ordered'.)

> 4) Does server-side ExecutionHandlers require some extra maintenance like
> shutting down after completing operation etc? OR is adding ExecutionHandler
> (on server side) to pipeline enough so the rest is handled by Netty? I'm
> asking because in one of previous threads I read about shutting down
> executors.

The Executor which is used by an ExecutionHandler needs to be shut
down when the server *completely* shuts down.  The latest SVN snapshot
provides a method called ExecutionHandler.releaseExternalResources(),
which shuts down the Executor.  (I think I need to write a better
example. :-)

HTH,

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




More information about the netty-users mailing list