Improving performance of ProtobufDecoder
IanS
iswett at yahoo.com
Wed Jul 14 13:16:14 EDT 2010
I found the performance of protocol buffers to be somewhat slow for small
messages, and discovered that it was much faster and produced less garbage
to read into a byte[] and parse from that for messages less than 4k.
Here is the new version of decode, which almost doubles the network
performance for me when using relatively small(ie: 100 byte) messages:
protected Object decode(ChannelHandlerContext ctx, Channel channel, Object
msg) throws Exception {
if (!(msg instanceof ChannelBuffer)) {
return msg;
}
ChannelBuffer buf = (ChannelBuffer) msg;
if(buf.readableBytes() <= 4096) {
byte[] bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);
if(extensionRegistry == null)
{
return prototype.newBuilderForType().mergeFrom(bytes).build();
}
else
{
return prototype.newBuilderForType().mergeFrom(bytes,
extensionRegistry).build();
}
}
else
{
if (extensionRegistry == null) {
return prototype.newBuilderForType().mergeFrom(
new ChannelBufferInputStream((ChannelBuffer) msg)).build();
} else {
return prototype.newBuilderForType().mergeFrom(
new ChannelBufferInputStream((ChannelBuffer) msg),
extensionRegistry).build();
}
}
}
I would be happy to have this integrated into the next release. Is the most
appropriate way to go about that to file a JIRA request?
Thanks, Ian
--
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Improving-performance-of-ProtobufDecoder-tp5293790p5293790.html
Sent from the Netty User Group mailing list archive at Nabble.com.
More information about the netty-users
mailing list