Hi All,
I'm writing a decoder extends CumulativeProtocolDecoder and I got a
performance problem.
I wonder if I misused CumulativeProtocolDecoder.
The message format is the fixed-length message which is defined by
FRAME_LENGTH.
The following is my doDecode method:
protected boolean doDecode(IoSession session, IoBuffer in,
ProtocolDecoderOutput out) throws Exception {
int remain = in.remaining();
if (remain >= FRAME_LENGTH){
byte [] data = new byte [FRAME_LENGTH];
while (remain >= FRAME_LENGTH){
in.get(data,0,FRAME_LENGTH);
out.write(data);
out.flush();
System.out.println("remain data:"+remain);
remain = in.remaining();
}
return false;
}
return false;
}
The server keep sending message to my client and I decode the message in
this doDecode.
In my test, the "remain data" in the console seemed to be keep going up util
got the java heap space outofmemoryError.
Three notes:
1> Why I always use return false: I don't understand the diff between true
or false. At first, I thought the when I got the enough data to put into the
out, I should use return true. But I got error. So I alway use false and
currently, the logic seems correct.
2> Why I use out.flush. I found if I don't do that, the messageReceived
method couldn't get correct every message. Some message will lost and others
may be duplicated.
3> The data transfer speed is about 1MB/s.
Any friends help me?
Thank you in advance!
--
Best Regards
DAI Jun