3

After my test, there is no difference in performance between Netty's NioEventLoopGroup and EpollEventLoopGroup. Why does Netty also provide EpollEventLoopGroup?

When the server maintains 1000 TCP links, there is no difference between CPU and memory of the server. Here is my code:

public class EpollServer {
        public static void main(String[] args) throws Exception {
            logger.info("port:"+System.getProperty("port", "8007"));
            logger.info("isUseEpoll:"+System.getProperty("isUserEpoll","true"));
            EventLoopGroup bossGroup;
            EventLoopGroup workerGroup;
            Class          clazz;
    
            if (useEpoll()) {
                bossGroup = new EpollEventLoopGroup(1);
                workerGroup = new EpollEventLoopGroup();
                clazz = EpollServerSocketChannel.class;
            }else{
                bossGroup = new NioEventLoopGroup(1);
                workerGroup = new NioEventLoopGroup();
                clazz = NioServerSocketChannel.class;
            }
    
            final EpollServerHandler epollHandler = new EpollServerHandler();
            try {
                ServerBootstrap b = new ServerBootstrap();
                logger.info("[socket Type]: {}", clazz.getSimpleName());
                b.group(bossGroup, workerGroup)
                        .channel(clazz)
                        .option(ChannelOption.SO_BACKLOG, 10001)
                        .childHandler(new ChannelInitializer<SocketChannel>() {
                            @Override
                            public void initChannel(SocketChannel ch) throws Exception {
                                ChannelPipeline p = ch.pipeline();
                                p.addLast(new LengthFieldBasedFrameDecoder(1024,0,2,0,2));
                                p.addLast(new SimpleChannelInboundHandler(){
                                    @Override
                                    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
                                        ByteBuf content = (ByteBuf) msg;
                                        ctx.channel().writeAndFlush(content.retain());
                                    }
                                });
    
                            }
                        });
   
                ChannelFuture f = b.bind(PORT).sync();
                f.channel().closeFuture().sync();
            } finally {
                bossGroup.shutdownGracefully();
                workerGroup.shutdownGracefully();
            }
        }


    private static boolean useEpoll() {
        if(isUseEpoll){
            return Epoll.isAvailable();
        }else{
            return false;
        }
    }
}
Kirby
  • 15,127
  • 10
  • 89
  • 104

1 Answers1

0

I can tell you that in "heavy load" scenarios there is definitely a performance difference in:

  • CPU usage
  • Memory usage
  • Allocations

Beside this the native epoll transport also supports multiple features that are not exposed by NIO itself.

Norman Maurer
  • 23,104
  • 2
  • 33
  • 31
  • I read the official wiki: [Native-transports](https://github.com/netty/netty/wiki/Native-transports). The wiki doesn't mention how much performance has improved, and I've tested it myself. How can I test to demonstrate the benefits of epolleventloopgroup?Thank you – JaneWen Chan Jun 29 '20 at 02:48