-1

I wrote a simple code to test the performance my Server

        while (true) {
            ByteBuf firstMessage = Unpooled.buffer(8);
            firstMessage.writeInt(1);
            firstMessage.writeInt(1);
            firstMessage.writeLong(1L);
            f.channel().writeAndFlush(firstMessage);
        }

After 30 seconds:

  • All memory occupied
  • Server stop receiving new messages

Sorry my English

user2413972
  • 1,355
  • 2
  • 9
  • 25

3 Answers3

0

Likely you are creating new buffers (on-heap) quicker than you can send them across the network on a single channel, so eventually they consume the whole heap and you'll have OOM problems.

Derek Troy-West
  • 2,469
  • 1
  • 24
  • 27
0

I think you'd better try to call firstMessage.release() after the flushing is done. In the ByteBuf specification, it is shown that the ByteBuffer is implementing ReferenceCounted.

Byungjoon Lee
  • 913
  • 6
  • 18
0

You don't need to keep recreating that buffer. Either release it inside the loop, or create it before the loop starts and just reset it inside the loop.

user207421
  • 305,947
  • 44
  • 307
  • 483