netty吃了100%的CPU

时间:2016-06-17 12:02:47

标签: java multithreading netty epoll

我正在netty上运行一个服务器,并发现一些线程在java服务器应用程序初始化后一段时间开始吃掉100%的CPU。我试图用不同数量的线程初始化boss和worker组,但结果是一样的。

它可能是什么原因?

EventLoopGroup bossGroup = new NioEventLoopGroup(); 
EventLoopGroup workerGroup = new NioEventLoopGroup(50);
try {
    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup)
    .channel(NioServerSocketChannel.class)
    .childHandler(new ChannelInitializer<SocketChannel>() { 
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast("ReadTimeOutHandler", new ReadTimeoutHandler(20));
            ch.pipeline().addLast(new streamDecoder());
            ch.pipeline().addLast(new streamEncoder());

            ch.pipeline().addLast(new validationHandler());
            ch.pipeline().addLast(new streamDecryptor());
            ch.pipeline().addLast(new streamEncryptor());
            ch.pipeline().addLast(new msgValidatedHandler());
         }
     })
     .option(ChannelOption.SO_BACKLOG, 128)
     .childOption(ChannelOption.SO_KEEPALIVE, true);  

1 个答案:

答案 0 :(得分:1)

Google sun.nio.ch.WindowsSelectorImpl$SubSelector high cpu的Google搜索引发了2015年的最后一次点击。您是否正在运行旧版本的Netty?

另请参阅https://github.com/netty/netty/issues/3857 - 您可能想尝试使用-Dorg.jboss.netty.epollBugWorkaround=true