Netty performance question

omsdw mgiedt at gmail.com
Sat Apr 25 15:53:33 EDT 2009


Hi -- I have a question on how best to configure Netty for maximum message
throughput.

I've created a new 'AggregatedDelimiterBasedFrameDecoder' that is
essentially identical to the DelimiterBasedFrameDecoder except that it
returns a List<ChannelBuffer> as opposed to a single ChannelBuffer on each
call to decode.

    @Override
    protected Object decode( ChannelHandlerContext ctx,
                             Channel channel,
                             ChannelBuffer buffer )
        throws Exception
    {
        final List<ChannelBuffer> frames = new ArrayList();
        ChannelBuffer frame = null;

        while( ( frame = nextFrame( ctx, channel, buffer ) ) != null )
        {
            frames.add( frame );
        }

        return frames.size() == 0 ? null : frames;
    }

    private final ChannelBuffer nextFrame( ChannelHandlerContext ctx,
                                           Channel channel,
                                           ChannelBuffer buffer )
        throws Exception
    {
       // this is an identical copy of the original decode from
DelimiterBasedFrameDecoder...
    }

And then my AggregatedStringDecoder looks like...

    public void handleUpstream( ChannelHandlerContext context,
                                ChannelEvent evt )
        throws Exception
    {
        if(! ( evt instanceof MessageEvent ) )
        {
            context.sendUpstream( evt );
            return;
        }

        final MessageEvent e = (MessageEvent) evt;
        if(!(e.getMessage() instanceof List))
        {
            context.sendUpstream(evt);
            return;
        }

        final List<ChannelBuffer> frames =
(List<ChannelBuffer>)e.getMessage();

        for( int i=0; i<frames.size(); i++ )
        {
            fireMessageReceived( context, e.getChannel(),
                frames.get( i ).toString( charsetName ) );
        }
    }

So far so good? Would you recommend any changes? Curious if you think in the
long run this is better than just one at a time? (Again, the goal here is to
improve throughput -- I'm also happy to contribute the code...)

Now I have a ExecutionHandler in between the AggregatedStringDecoder and my
BusinessLogicHandler in the pipeline factory. 

    public ChannelPipeline getPipeline()
        throws Exception
    {
        final ChannelPipeline pipeline = super.getPipeline();

        pipeline.addLast( "framer",
            new AggregatedDelimiterBasedFrameDecoder(
                BUFFER, Delimiters.lineDelimiter() ) );

        pipeline.addLast( "decoder", new AggregatedStringDecoder( "UTF-8" )
);
        pipeline.addLast( "encoder", new StringEncoder( "UTF-8" ) );

        pipeline.addLast( "executor", new ExecutionHandler(
            new OrderedMemoryAwareThreadPoolExecutor(
                THREADS,
                MAX_CHANNEL_MEMORY_SIZE,
                MAX_TOTAL_MEMORY_SIZE ) ) );

        pipeline.addLast( "handler", handler );

        return pipeline;
    }

Shouldn't each call to 'fireMessageReceived' be handled in a separate thread
by the Executor? (I'm not seeing this) I also don't think I *really*
understand the difference between the ordered and non-ordered executors.

TIA,
-Matt


-- 
View this message in context: http://n2.nabble.com/Netty-performance-question-tp2712571p2712571.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list