前一陣子剛整理完RocketMQ4.3.x版本的相關配置的工作,接下來就來測試一下改變參數會帶來什麼好的結果 首先我就選中了useEpollNativeSelector 這個參數 預設這個參數是 false 這個參數的意思就是是否啟用Epoll IO模型。Linux環境建議開啟 然後我就打開了這個參 ...
前一陣子剛整理完RocketMQ4.3.x版本的相關配置的工作,接下來就來測試一下改變參數會帶來什麼好的結果
首先我就選中了useEpollNativeSelector 這個參數
預設這個參數是 false
這個參數的意思就是是否啟用Epoll IO模型。Linux環境建議開啟
然後我就打開了這個參數試試看看會不會生效
首先是namesrv 弄了一個配置文件指向啟動
然後啟動namesrv
sh bin/mqnamesrv -c conf/namesrv.conf
很不幸拋出了一個異常
java.lang.IllegalStateException: incompatible event loop type: io.netty.channel.nio.NioEventLoop at io.netty.channel.AbstractChannel$AbstractUnsafe.register(AbstractChannel.java:411) at io.netty.channel.SingleThreadEventLoop.register(SingleThreadEventLoop.java:72) at io.netty.channel.SingleThreadEventLoop.register(SingleThreadEventLoop.java:60) at io.netty.channel.MultithreadEventLoopGroup.register(MultithreadEventLoopGroup.java:64) at io.netty.bootstrap.AbstractBootstrap.initAndRegister(AbstractBootstrap.java:320) at io.netty.bootstrap.AbstractBootstrap.doBind(AbstractBootstrap.java:271) at io.netty.bootstrap.AbstractBootstrap.bind(AbstractBootstrap.java:235) at org.apache.rocketmq.remoting.netty.NettyRemotingServer.start(NettyRemotingServer.java:212) at org.apache.rocketmq.namesrv.NamesrvController.start(NamesrvController.java:156) at org.apache.rocketmq.namesrv.NamesrvStartup.start(NamesrvStartup.java:154) at org.apache.rocketmq.namesrv.NamesrvStartup.main0(NamesrvStartup.java:58) at org.apache.rocketmq.namesrv.NamesrvStartup.main(NamesrvStartup.java:51)
通過拋出的異常追查一下源碼
發現在執行構造函數的時候初始化的是下麵代碼 90-143行
public NettyRemotingServer(final NettyServerConfig nettyServerConfig, final ChannelEventListener channelEventListener) { super(nettyServerConfig.getServerOnewaySemaphoreValue(), nettyServerConfig.getServerAsyncSemaphoreValue()); this.serverBootstrap = new ServerBootstrap(); this.nettyServerConfig = nettyServerConfig; this.channelEventListener = channelEventListener; int publicThreadNums = nettyServerConfig.getServerCallbackExecutorThreads(); if (publicThreadNums <= 0) { publicThreadNums = 4; } this.publicExecutor = Executors.newFixedThreadPool(publicThreadNums, new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); @Override public Thread newThread(Runnable r) { return new Thread(r, "NettyServerPublicExecutor_" + this.threadIndex.incrementAndGet()); } }); this.eventLoopGroupBoss = new NioEventLoopGroup(1, new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); @Override public Thread newThread(Runnable r) { return new Thread(r, String.format("NettyBoss_%d", this.threadIndex.incrementAndGet())); } }); if (useEpoll()) { this.eventLoopGroupSelector = new EpollEventLoopGroup(nettyServerConfig.getServerSelectorThreads(), new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); private int threadTotal = nettyServerConfig.getServerSelectorThreads(); @Override public Thread newThread(Runnable r) { return new Thread(r, String.format("NettyServerEPOLLSelector_%d_%d", threadTotal, this.threadIndex.incrementAndGet())); } }); } else { this.eventLoopGroupSelector = new NioEventLoopGroup(nettyServerConfig.getServerSelectorThreads(), new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); private int threadTotal = nettyServerConfig.getServerSelectorThreads(); @Override public Thread newThread(Runnable r) { return new Thread(r, String.format("NettyServerNIOSelector_%d_%d", threadTotal, this.threadIndex.incrementAndGet())); } }); } loadSslContext(); }
也就是說這裡接收鏈接的線程池 eventLoopGroupBoss 永遠都是 NioEventLoopGroup 如果設置了useEpollNativeSelector=true就會初始化EpollEventLoopGroup這個類處理請求
這樣就會造成兩種線程模型的不相容狀態
導致出現異常 java.lang.IllegalStateException: incompatible event loop type: io.netty.channel.nio.NioEventLoop
按常理說阿裡的人不會出現這樣的低級錯誤啊
回頭又看了看github的bug列表果然有人提這個問題bug還是開啟狀態
????為什麼?
難道是我使用配置有問題嗎?還是哪裡理解有誤那?知道的網友可以告訴我啊!!!!
最新消息我也提交了bug維護人員已經修改bug但是要等到4.4.1版本才可以修正