I have a server reading inbound newline-delimited strings. The pipeline looks like this:
...
pipeline.addLast("framer",
new DelimiterBasedFrameDecoder(65535, Delimiters.lineDelimiter()));
// plain old strings
pipeline.addLast("decoder", new StringDecoder());
// callback to handler
pipeline.addLast("handler", new ConnectorHandler(collector));
...
When I change the decoder to the following:
pipeline.addLast("framer",
new DelimiterBasedFrameDecoder(65535,
new ChannelBuffer[] { ChannelBuffers.wrappedBuffer(
new byte[] {'\n'})}));
I get a 3-4X increase in server speed. I don’t understand why this would be the case. The inbound strings vary betweeen about 1K-4K in length, around 10K strings/sec. Looking at the source code, it appears that it cycles through all the delimiters to find the one yielding the minimum frame length — by inspection, I don’t see how looking for only one delimiter would result in such a performance gain over looking for two delimiters. I am tempted to try to write my own decoder but I would like to understand what’s going on here. Any insight would be appreciated.
thats exactly the case.. looking only for one is much more cheap.