Improving performance of ProtobufDecoder
"이희승 (Trustin Lee)"
trustin at gmail.com
Mon Aug 16 02:00:36 EDT 2010
Thank Ian and Shay,
I've just applied the patch. Thanks a lot for your patience!
Cheers,
Trustin
On 07/16/2010 05:41 AM, IanS wrote:
>
> I believe most of the difference is that CodedInputStream allocates a 4096
> byte buffer every time, which can start becoming a lot of overhead for many
> small messages. I tried this based on a forum post I can't seem to locate
> right now.
>
> Thanks for the suggestion about array, I changed the method to a more
> 'zero-copy' approach now:
>
> protected Object decode(ChannelHandlerContext ctx, Channel channel, Object
> msg) throws Exception {
> if (!(msg instanceof ChannelBuffer)) {
> return msg;
> }
>
> ChannelBuffer buf = (ChannelBuffer) msg;
> if(buf.hasArray()) {
> if(extensionRegistry == null) {
> return prototype.newBuilderForType().mergeFrom(buf.array(),
> buf.arrayOffset(), buf.readableBytes()).build();
> }
> else {
> return prototype.newBuilderForType().mergeFrom(buf.array(),
> buf.arrayOffset(), buf.readableBytes(), 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();
> }
> }
> }
>
--
what we call human nature in actuality is human habit
http://gleamynode.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 293 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20100816/b9725a5d/attachment.bin
More information about the netty-users
mailing list