Netty parameter setting recommendation

Netty parameter setting

BossGroup

  • Conclusion
    When you use BossGroup and WorkerGroup, BossGroup recommends setting the number of ports to monitor, that is, set as many ports as there are monitors.
  • The reason is that
    netty's BossGroup has multiple threads (that is, NioEventLoop). When a connection is established, one thread is responsible for accepting, and the other threads are responsible for business processing.
    When using the two thread pools of BossGroup and WorkerGroup, other threads of BossGroup will not work; but when your program needs to bind other ports, it will take a thread from BossGroup to bind other ports.

WorkerGroup

  • Conclusion
    The recommended setting is the number of cores*2 (without modifying ioRatio).
  • Reason
    Generally, programs are divided into I/O-intensive tasks and CPU-intensive tasks
    . For CPU-intensive tasks, theoretically "the number of threads = the number of CPU cores" is appropriate. However, the number of threads in practical applications is generally set to "CPU core number + 1". Because threads may be blocked due to memory page failure or other reasons, setting one more thread can ensure CPU utilization.
    For I/O-intensive types, assuming that the ratio of IO time consumption to CPU time consumption is R, the calculation formula is as follows:
    optimal number of threads = number of CPU cores * (1 + R)
    and the number of default thread pools of Netty is assumed The ratio of I/O time consumption to CPU time consumption is 1:1. In fact, Netty has a parameter called ioRatio, which defaults to 50. It means that in a round event loop, a single I/O thread executes I/O events and The time-consuming ratio of executing asynchronous tasks is 1:1. Equivalent to R = 1, substituting the above formula, you can get that the default thread pool size of Netty is naturally the
    default thread pool size = number of CPU cores * (1 + 1)

leakDetectorLevel

  • DISABLED (disabled): no memory leak detection;
  • SIMPLE (simple operation): Sampling detection, and only record some method calls, less consumption, may delay reporting when there is a leak, the default level;
  • ADVANCED (advanced): Sampling detection, recording the last few call records of the object, and reporting may be delayed when there is a leak;
  • PARANOID (paranoia): Leak detection is performed every time an object is created, and the object's recent detailed call records are recorded. It is a more aggressive memory leak detection level and consumes the most. It is recommended to use it only during testing.

Guess you like

Origin blog.csdn.net/baidu_29609961/article/details/127003708