Analysis Netty -transport buddo source assembly of (a)

dubbo 2.5.10 version, netty netty still using the 3.10.5 version, we can see from the following code, SPI default is "netty", rather than "netty4".

package com.alibaba.dubbo.remoting;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.Adaptive;
import com.alibaba.dubbo.common.extension.SPI;

import javax.sound.midi.Receiver;

/**
 * Transporter. (SPI, Singleton, ThreadSafe)
 * <p>
 * <a href="http://en.wikipedia.org/wiki/Transport_Layer">Transport Layer</a>
 * <a href="http://en.wikipedia.org/wiki/Client%E2%80%93server_model">Client/Server</a>
 *
 * @see com.alibaba.dubbo.remoting.Transporters
 */
@SPI("netty")
public interface Transporter {

Whether NettyClient, or create a Channel NettyServer factory class to create ChannelFactory are the same way, the code is as follows:

// ChannelFactory's closure has a DirectMemory leak, using static to avoid
// https://issues.jboss.org/browse/NETTY-424
private static final ChannelFactory channelFactory = new NioClientSocketChannelFactory(
    Executors.newCachedThreadPool(new NamedThreadFactory("NettyClientBoss", true)),
    Executors.newCachedThreadPool(new NamedThreadFactory("NettyClientWorker", true)),
    Constants.DEFAULT_IO_THREADS);

As the name suggests, ChannelFactory class is used to create the Channel, and Channel that is used to do it? Summarized in one sentence: all the I / O operations are implemented by the Channel. From the above code can be seen in Dubbo created two I / O thread pool, respectively Boss and Workder thread pool thread pool, this two thread pools are initialized to "borderless," the cached thread pool that is just start is "generosity", but in fact the default maximum thread Boss allows only one thread, the thread pool maximum number of threads Work specified for Constants.DEFAULT_IO_THREADS, namely: both the number of +1 CPU core with a 32 to take a minimum value. code show as below:

private static final int DEFAULT_BOSS_COUNT = 1;
public NioClientSocketChannelFactory(
        Executor bossExecutor, Executor workerExecutor, int workerCount) {
    this(bossExecutor, workerExecutor, DEFAULT_BOSS_COUNT, workerCount);
}
public static final int DEFAULT_IO_THREADS = Math.min(Runtime.getRuntime().availableProcessors() + 1, 32);

 

Guess you like

Origin www.cnblogs.com/frankyou/p/11416755.html