xuxueli / xxl-rpc

A high performance, distributed RPC framework.(分布式服务框架XXL-RPC)
http://www.xuxueli.com/xxl-rpc/
Apache License 2.0
623 stars 406 forks source link

Why NettyHttpConnectClient Use so many NioEventGroups? #32

Closed qixiaobo closed 4 years ago

qixiaobo commented 4 years ago

In XXL-JOB-ADMIN , we can see a lot of nio group if some error occurs. For some reasons, we may register some unreachable ip to xxl-job-admin. In xxl-job-admin, we should invoke XxlRpcReferenceBean We can see code below

    // do invoke
client.asyncSend(finalAddress, xxlRpcRequest);

In this sense , XXL_RPC may produces a NettyHttpConnectionClient But this way may not work fine

 public void init(String address, final Serializer serializer, final XxlRpcInvokerFactory xxlRpcInvokerFactory) throws Exception {

        if (!address.toLowerCase().startsWith("http")) {
            address = "http://" + address;  // IP:PORT, need parse to url
        }

        this.address = address;
        URL url = new URL(address);
        this.host = url.getHost();
        int port = url.getPort()>-1?url.getPort():80;

        this.group = new NioEventLoopGroup();
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(group)
                .channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel channel) throws Exception {
                        channel.pipeline()
                                /*.addLast(new HttpResponseDecoder())
                                .addLast(new HttpRequestEncoder())*/
                                .addLast(new HttpClientCodec())
                                .addLast(new HttpObjectAggregator(5*1024*1024))
                                .addLast(new NettyHttpClientHandler(xxlRpcInvokerFactory, serializer));
                    }
                })
                .option(ChannelOption.SO_KEEPALIVE, true);
        this.channel = bootstrap.connect(host, port).sync().channel();

        this.serializer = serializer;

        // valid
        if (!isValidate()) {
            close();
            return;
        }

        logger.debug(">>>>>>>>>>> xxl-rpc netty client proxy, connect to server success at host:{}, port:{}", host, port);
    }

I don't think we should use a new NioEventGroup here.

qixiaobo commented 4 years ago

duplicate to https://github.com/xuxueli/xxl-rpc/issues/16

qixiaobo commented 4 years ago

But I still think it's unnecessary ,even connect to server successfully. You can have a look at dubbo's source https://github.com/apache/dubbo/blob/ed7be11af9a8a9dddb4d23eea089f3890391575b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClient.java#L58

xuxueli commented 4 years ago

你好,问题已修复并推送master分支,可以pull master体验下。将会跟随下个版本发布。