且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在处理程序中组装一个Netty消息

更新时间:2022-03-04 01:12:18

我如果您要实现自己的FrameDecoder,请认为您将获得***性能。这将允许您缓冲所有数据,直到您真正需要将其分派给链中的下一个处理程序。请参阅 FrameDecoder apidocs。

I think you would get the best performance if you would implement your own FrameDecoder. This would allow you to buffer all the data till you really need to dispatch it to the next Handler in the chain. Please refer to the FrameDecoder apidocs.

如果您不想自己处理CRLF的检测,还可以保留DelimiterBasedFrameDecoder并在其后面添加一个自定义FrameDecoder来组装ChannelBuffers代表一行文本。

If you don't want to handle the detect of CRLF by yourself it would also be possible to keep the DelimiterBasedFrameDecoder and just add a custom FrameDecoder behind it to assemble the ChannelBuffers that represent a line of text.

在这两种情况下,FrameDecoder都会尽量减少内存副本,尝试只是包装缓冲区而不是每次都复制它们。

In both cases FrameDecoder will take care to minimize memory copies as much as possible by try to just "wrap" buffers and not copy them each time.

如果你想要获得***的表现,那就选择第一种方法,如果你想要第二种方法,那就很容易了;)

That said if you want to have the best performance go with the first approach, if you want it easy go with the second ;)