Netty 4.0.19 クライアント サーバー アプリのパフォーマンスが遅いため、コーデックが悪いのではないかと疑っています。単純なメッセージ オブジェクトは、整数 ID と、それに付随する長さを持つ 2 つの文字列で構成されます。ReplayingDecoder で CharsetDecoder を使用して、バイトから文字列を取得します。
msg.value = charsetDecoder.decode(in.readBytes(msg.valueLen).nioBuffer()).toString();
checkpoint(CDRMessageDecoderState.FIELD_MASK_METHOD);
ByteToMessageDecoder では、シリアル化に高速な Kryo ライブラリを使用します (ここで間接ヒープ バッファーを作成することは避けられますか?)。
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;
}
現在、ReplayingDecoder は何とか ByteToMessageDecoder を上回っているようです。また、DefaultEventExecutorGroup でいくつかの単純なバックエンド ロジックを実行しています (イベント スレッドをブロックしないと思います)。これは HashMaps を検索し、writeAndFlush を使用して ChannelHandlerContext にメッセージを書き込みます。ありがとう