performance issues with HttpRequestDecoder?

Shivaram Lingamneni slingamn at cs.stanford.edu
Mon Aug 16 05:04:37 EDT 2010


I've been trying to write a simple HTTP-based RPC server using Netty 3.2.1.
I basically took the Snoop example server and deleted code from it :-)

I profiled my application and found that a lot of time was being spent in
HttpRequestDecoder.decode. More specifically, it seems to be spinning on
ReplayingDecoderBuffer.readUnsignedByte (and its callee checkReadableBytes).
Has anyone run into this before?

This is my pipeline:

ChannelPipeline pipeline = pipeline();
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("aggregator", new HttpChunkAggregator(1048576));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("deflater", new HttpContentCompressor());
HTTPRequestHandler handler = new HTTPRequestHandler();
handler.setBridge(bridge);
pipeline.addLast("handler", handler);

And this is the relevant part of my handler:

public void messageReceived(ChannelHandlerContext ctx, MessageEvent event)
throws Exception {
HttpRequest request = (HttpRequest) event.getMessage();
ChannelBuffer content = request.getContent();
String contentString = content.toString(CharsetUtil.UTF_8);
String rpcResponse = bridge.performRPC(contentString);

// Decide whether to close the connection or not.
boolean keepAlive = isKeepAlive(request);

// Build the response object.
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
response.setContent(ChannelBuffers.copiedBuffer(rpcResponse,
CharsetUtil.UTF_8));
response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");

if (keepAlive) {
// Add 'Content-Length' header only for a keep-alive connection.
response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes());
}

// Write the response.
ChannelFuture future = event.getChannel().write(response);

// Close the non-keep-alive connection after the write operation is done.
if (!keepAlive) {
future.addListener(ChannelFutureListener.CLOSE);
}
}

The expensive code path goes through future.addListener(); I've attached a
clumsy pair of screenshots from my profiler (YourKit 8.x).

Thanks very much for your time.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20100816/4c15d918/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot.png
Type: image/png
Size: 102200 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20100816/4c15d918/attachment-0002.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot-1.png
Type: image/png
Size: 89768 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20100816/4c15d918/attachment-0003.png 


More information about the netty-users mailing list