2016-06-17 8 views
1

私はnetty上でサーバを稼働しており、しばらくしてからJavaサーバアプリケーションによって初期化されたスレッドがCPUの100%を食べ始めていることが分かりました。ボスとワーカーグループをスレッド数を変えて初期化しようとしましたが、結果は同じです。nettyはCPUの100%を食べます

何故その理由が考えられますか?

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); 
+0

どのスレッドが100%CPUを使用していますか?彼らはNettyのスレッドですか?また、なぜworkergroupのための50スレッド? – Sneh

+0

私はスレッドの数が絶えず増加し、減少していないことがわかります。 多数の同時接続の高速処理のために、ワーカーグループ用のスレッドが50個設定されていました。しかし、5作品はかなり良いものに減少しました。 – George

+0

実行しているコードを確認するためにスレッドダンプを作成しようとしましたか? –

答えて

0

私はCPU時間のほとんどを消費するスレッドはnioEventLoopGroup -3-2,1,4と CPUのサンプルを示しio.netty.channel.nio.NioEventLoop.select()にしていることが判明しました自己時間の頂点にCPUの消費がある。

私はnioEventLoopGroup-3-2のスレッドダンプを作ったし、結果は以下の通りである:

"nioEventLoopGroup-3-2" #15 prio=10 os_prio=2 tid=0x00000000135ba800 nid=0x61c runnable [0x00000000142fe000] 
    java.lang.Thread.State: RUNNABLE 
    at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method) 
    at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(Unknown Source) 
    at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(Unknown Source) 
    at sun.nio.ch.WindowsSelectorImpl.doSelect(Unknown Source) 
    at sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source) 
    - locked <0x00000000e097abc8> (a io.netty.channel.nio.SelectedSelectionKeySet) 
    - locked <0x00000000e097abb8> (a java.util.Collections$UnmodifiableSet) 
    - locked <0x00000000e097ab38> (a sun.nio.ch.WindowsSelectorImpl) 
    at sun.nio.ch.SelectorImpl.select(Unknown Source) 
    at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:622) 
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:310) 
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:110) 
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) 
    at java.lang.Thread.run(Unknown Source) 

    Locked ownable synchronizers: 
    - None 

私もsun.nio.ch.WindowsSelectorImpl $ SubSelectorで忙しいスレッドの絶えず増加数を参照してください。何かご意見は?

0

グーグリングsun.nio.ch.WindowsSelectorImpl$SubSelector high cpuは、2015年に最後から数回ヒットします。古いバージョンのNettyを使用していますか?

https://github.com/netty/netty/issues/3857も参照してください。-Dorg.jboss.netty.epollBugWorkaround=trueで試してみてください。

+0

これはjstackがWindows 2012 R2で示したものですが、ubuntu 12の下ではここで述べたものとほぼ同じです(100%同じ場合)。https://github.com/netty/netty/issues/327 質問は設定できますこのようなコードの中でシステムプロパティが正しい? public static void main(String [] args)例外をスローします。{ \t System.setProperty( "org.jboss.netty.epollBugWorkaround"、 "true"); ... – George

+0

コードでプロパティを設定できるはずですが、Nettyクラスがロードされる前に、可能な限り早く行う必要があります。 main()の最初の行はおそらく最も簡単です。 – AngerClown

+0

お返事ありがとうございます。 – George

0

お返事ありがとうございます。私はまた、スレッドの数が増加していることに気付きました。 (Ubuntuの12歳未満)のCPU jstackを消費するスレッドの一つに次のことを示しています。私はこの問題は、この問題DefaultEventExecutorGroup threads are keep growing and server is slow responding to requests

に似ていますが、私はまさに私の中で何が間違っているかわからないと仮定し

"nioEventLoopGroup-11-4" #84 prio=10 os_prio=0 tid=0x00007f9fb0057000 nid=0x4307 runnable [0x00007f9fa4f79000] 
    java.lang.Thread.State: RUNNABLE 
     at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method) 
     at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269) 
     at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:79) 
     at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86) 
     - locked <0x00000000c303e988> (a io.netty.channel.nio.SelectedSelectionKeySet) 
     - locked <0x00000000c303ffa8> (a java.util.Collections$UnmodifiableSet) 
     - locked <0x00000000c303e8f0> (a sun.nio.ch.EPollSelectorImpl) 
     at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97) 
     at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:622) 
     at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:310) 
     at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:110) 
     at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) 
     at java.lang.Thread.run(Thread.java:745) 

コード、および修正プログラムの実装方法について説明します。

関連する問題