Skip to content

lenovo dtc master merge request, netty4 support epoll for nio on linux os - #4493

Closed
lenovoDTC wants to merge 3 commits into
apache:masterfrom
lenovoDTC:dtc_master
Closed

lenovoDTC wants to merge 3 commits into
apache:masterfrom
lenovoDTC:dtc_master

Conversation

@lenovoDTC

Copy link
Copy Markdown

What is the purpose of the change

netty4 support epoll for nio in linux os

Brief changelog

dubbo-remoting/dubbo-remoting-netty4:NettyClient
dubbo-remoting/dubbo-remoting-netty4:NettyServer

Verifying this change

Need to be validated under Linux OS

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a GITHUB_issue field for the change (usually before you start working on it). Trivial changes like typos do not require a GITHUB issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [Dubbo-XXX] Fix UnknownException when host config not exist #XXX. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Run mvn clean install -DskipTests=false & mvn clean test-compile failsafe:integration-test to make sure unit-test and integration-test pass.
  • If this contribution is large, please follow the Software Donation Guide.

@lenovoDTC lenovoDTC changed the title Dtc master lenovo dtc master merge request, netty4 support epoll for nio on linux os Jul 9, 2019
*/
package org.apache.dubbo.remoting.transport.netty4;

import io.netty.bootstrap.Bootstrap;

@beiwei30 beiwei30 Jul 16, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
* the os name
*/
private static final String osName = SystemPropertyUtil.get("os.name").toLowerCase(Locale.UK).trim();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Locale.ENGLISH instead of Locale.UK

* netty client bootstrap
*/
private static final NioEventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(Constants.DEFAULT_IO_THREADS, new DefaultThreadFactory("NettyClientWorker", true));
private static final EventLoopGroup eventLoopGroup = "linux".equals(osName) ? new EpollEventLoopGroup(Constants.DEFAULT_IO_THREADS, new DefaultThreadFactory("NettyClientWorker", true)): new NioEventLoopGroup(Constants.DEFAULT_IO_THREADS, new DefaultThreadFactory("NettyClientWorker", true));

@beiwei30 beiwei30 Jul 16, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls. pay attention to line wrap, which should be 120 column wide. Is it better to rewrite like this:

    private static EventLoopGroup eventLoopGroup() {
        String osName = SystemPropertyUtil.get("os.name").toLowerCase(Locale.ENGLISH).trim();
        return "linux".equals(osName) ?
                new EpollEventLoopGroup(Constants.DEFAULT_IO_THREADS, new DefaultThreadFactory("NettyClientWorker", true)) :
                new NioEventLoopGroup(Constants.DEFAULT_IO_THREADS, new DefaultThreadFactory("NettyClientWorker", true));
    }

final NettyClientHandler nettyClientHandler = new NettyClientHandler(getUrl(), this);
bootstrap = new Bootstrap();
bootstrap.group(nioEventLoopGroup)
bootstrap.group(eventLoopGroup)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we have two factory methods, then we can change this logic to

        bootstrap.group(eventLoopGroup())
                .option(ChannelOption.SO_KEEPALIVE, true)
                .option(ChannelOption.TCP_NODELAY, true)
                .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
                //.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, getTimeout())
                .channel(socketChannelClass());

socketChannelClass()

    private static Class<? extends SocketChannel> socketChannelClass() {
        String osName = SystemPropertyUtil.get("os.name").toLowerCase(Locale.ENGLISH).trim();
        return "linux".equals(osName) ? EpollSocketChannel.class : NioSocketChannel.class)
    }

/**
* the os name
*/
private static final String osName = SystemPropertyUtil.get("os.name").toLowerCase(Locale.UK).trim();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

*/
package org.apache.dubbo.remoting.transport.netty4;

import io.netty.bootstrap.ServerBootstrap;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

new DefaultThreadFactory("NettyServerWorker", true));

Class<? extends ServerChannel> channelServerHandler = null;
if ("linux".equals(osName)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls. consider to introduce factory method too.

@beiwei30 beiwei30 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lenovoDTC pls. check my comments.

@beiwei30

Copy link
Copy Markdown
Member

pls. also take a look at #2738 and #4012, both are for epoll support.

@lexburner

Copy link
Copy Markdown
Contributor

You can replace

String osName = SystemPropertyUtil.get("os.name").toLowerCase(Locale.ENGLISH).trim();
"linux".equals(osName)

with

io.netty.channel.epoll.isAvailable()

In fact, some low version Linux doesn't support epoll.

Furthermore, support epoll can be configurable. It is better to set a param in the dubbo url to let dubbo user determine whether to use epoll in Linux. Such as me, I prefer to use NioEventLoop because of its compatibility, maybe there are many bugs.

@lexburner

Copy link
Copy Markdown
Contributor

There were some pull requests suggest that Dubbo support epoll, you can reference them
#2738

@Moriadry-zz Moriadry-zz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't means all linux system can support epoll transport. Maybe io.netty.channel.epoll.isAvailable() is a good choice. Also, we has discussed the performance of epoll before, but no explicit conclusion was found. pls check #4012

@lexburner lexburner closed this Jul 30, 2019
@htynkn htynkn mentioned this pull request Sep 2, 2019
@beiwei30

beiwei30 commented Sep 5, 2019

Copy link
Copy Markdown
Member

why close this pull request? let's keep it open.

@beiwei30 beiwei30 reopened this Sep 5, 2019
@beiwei30 beiwei30 added this to the 2.7.5 milestone Sep 5, 2019
@CLAassistant

CLAassistant commented Sep 6, 2019 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@beiwei30

Copy link
Copy Markdown
Member

since there's conflict and the original author fails to respond to the code review, I propose a new pull request #5680 to address this.

@chickenlj chickenlj closed this Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants