I am suspecting bad codec for the slow performance of my Netty 4.0.19 client server app. The simple message object consists of an integer id and two strings with their accompanying lengths. I use CharsetDecoder in ReplayingDecoder to get string from bytes:
msg.value = charsetDecoder.decode(in.readBytes(msg.valueLen).nioBuffer()).toString();
checkpoint(CDRMessageDecoderState.FIELD_MASK_METHOD);
In ByteToMessageDecoder I use fast Kryo library for serialization (can creating the indirect heap buffer here be avoided?):
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception
{
if (!buffer.isReadable())
return;
// read header
if (contentSize == 0) {
contentSize = buffer.readInt();
}
if (buffer.readableBytes() < contentSize) {
return;
}
// read content
byte [] buf = new byte[buffer.readableBytes()];
buffer.readBytes(buf);
Input in = new Input(buf);
out.add(kryoCodec.readObject(in, CDRMessage.class));
contentSize = 0;
}
Currently, ReplayingDecoder seems to somehow outperform ByteToMessageDecoder. Also, I have some simple backend logic running in DefaultEventExecutorGroup (so I don't think it blocks the event thread), which looks up HashMaps and writes the messages to the ChannelHandlerContext, with writeAndFlush. Thanx