Improving performance of ProtobufDecoder
Shay Banon
kimchy at gmail.com
Thu Jul 15 11:37:50 EDT 2010
It would be interesting to understand where the performance improvement is
coming from. I assume its because protobuf parses a byte[] faster then
InputStream (god knows why...) and not because readBytes and then working on
it is faster than ChannelBufferInputStream?
By the way, with the new ChannelBuffer#array method, you can dispence with
the array copy (readBytes) and pass the array itself (with the correct
postion and length, of course) if its available.
-shay.banon
On Wed, Jul 14, 2010 at 8:16 PM, IanS <iswett at yahoo.com> wrote:
>
> 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.
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20100715/379d327e/attachment-0001.html
More information about the netty-users
mailing list