欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

RocketMQ4.3.X关于设置useEpollNativeSelector = true报错问题

程序员文章站 2024-01-30 11:46:34
前一阵子刚整理完RocketMQ4.3.x版本的相关配置的工作,接下来就来测试一下改变参数会带来什么好的结果 首先我就选中了useEpollNativeSelector 这个参数 默认这个参数是 false 这个参数的意思就是是否启用Epoll IO模型。Linux环境建议开启 然后我就打开了这个参 ......

前一阵子刚整理完rocketmq4.3.x版本的相关配置的工作,接下来就来测试一下改变参数会带来什么好的结果

首先我就选中了useepollnativeselector 这个参数

默认这个参数是 false

这个参数的意思就是是否启用epoll io模型。linux环境建议开启


然后我就打开了这个参数试试看看会不会生效

首先是namesrv 弄了一个配置文件指向启动

RocketMQ4.3.X关于设置useEpollNativeSelector = true报错问题

然后启动namesrv

sh bin/mqnamesrv -c conf/namesrv.conf 

RocketMQ4.3.X关于设置useEpollNativeSelector = true报错问题

很不幸抛出了一个异常

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还是开启状态

 

RocketMQ4.3.X关于设置useEpollNativeSelector = true报错问题

????为什么?

难道是我使用配置有问题吗?还是哪里理解有误那?知道的网友可以告诉我啊!!!!