Avoid losing resources on waking up netty

167 Views Asked by At

I want to avoid spending a lot of CPU resources on waking up netty's thread. Every time the packet is flushed, the netty is wakened up. When I have a lot of packet sending I have a lot of these wake-ups, which is really hard for the CPU to process. How to make it spend less time on waking up, I found something like SelectStrategy.BUSY_WAIT, but as soon as I pick this option, my CPU is at 20% at all times. Is there a way to do something like delayed sleep/awaiting for wakeup?

I also tried to merge EventLoops of channels, but it seems that every channel has its own EventLoop.

1

There are 1 best solutions below

4
Norman Maurer On

There are multiple EventLoops and these are shared between Channels. How many of these are used is depending on how netty is configured and how the Channels are bootstrapped.

Regarding the wakups you might be able to reduce the overhead by do one of these:

  • Only flush from within the EventLoop.
  • Call write multiple times before call flush if you need to do it from outside the EventLoop.
  • Pack multiple messages into one "object" pass it to writeAndFlush(...) and have your own ChannelOutboundHandler that "decompose" this object into messages.