Java Code Examples for io.netty.channel.nio.NioEventLoopGroup#setIoRatio()

The following examples show how to use io.netty.channel.nio.NioEventLoopGroup#setIoRatio() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyServer.java    From flashback with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private ProxyServer(final Builder builder) {
  _acceptorGroup =
      new NioEventLoopGroup(2, new NamedThreadFactory("Client acceptor group"), SelectorProvider.provider());
  _upstreamWorkerGroup =
      new NioEventLoopGroup(8, new NamedThreadFactory("Client worker group"), SelectorProvider.provider());
  _upstreamWorkerGroup.setIoRatio(80);
  _downstreamWorkerGroup =
      new NioEventLoopGroup(8, new NamedThreadFactory("Server worker group"), SelectorProvider.provider());
  _downstreamWorkerGroup.setIoRatio(80);
  _host = builder._host;
  _port = builder._port;
  _serverConnectionIdleTimeout = builder._serverChannelIdleTimeout;
  _clientConnectionIdleTimeout = builder._clientChannelIdleTimeout;
  _connectionFlowRegistry = builder._connectionFlowRegistry;
  _proxyModeControllerFactory = builder._proxyModeControllerFactory;
}
 
Example 2
Source File: Connector.java    From serve with Apache License 2.0 5 votes vote down vote up
public static EventLoopGroup newEventLoopGroup(int threads) {
    if (useNativeIo && Epoll.isAvailable()) {
        return new EpollEventLoopGroup(threads);
    } else if (useNativeIo && KQueue.isAvailable()) {
        return new KQueueEventLoopGroup(threads);
    }

    NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(threads);
    eventLoopGroup.setIoRatio(ConfigManager.getInstance().getIoRatio());
    return eventLoopGroup;
}
 
Example 3
Source File: ProxyThreadPools.java    From g4proxy with Apache License 2.0 5 votes vote down vote up
public ProxyThreadPools(SelectorProvider selectorProvider, int incomingAcceptorThreads, int incomingWorkerThreads, int outgoingWorkerThreads, String serverGroupName, int serverGroupId) {
    clientToProxyAcceptorPool = new NioEventLoopGroup(incomingAcceptorThreads, new CategorizedThreadFactory(serverGroupName, "ClientToProxyAcceptor", serverGroupId), selectorProvider);

    clientToProxyWorkerPool = new NioEventLoopGroup(incomingWorkerThreads, new CategorizedThreadFactory(serverGroupName, "ClientToProxyWorker", serverGroupId), selectorProvider);
    clientToProxyWorkerPool.setIoRatio(90);

    proxyToServerWorkerPool = new NioEventLoopGroup(outgoingWorkerThreads, new CategorizedThreadFactory(serverGroupName, "ProxyToServerWorker", serverGroupId), selectorProvider);
    proxyToServerWorkerPool.setIoRatio(90);
}
 
Example 4
Source File: AbstractNettyServer.java    From spring-boot-protocol with Apache License 2.0 5 votes vote down vote up
protected EventLoopGroup newBossEventLoopGroup() {
        EventLoopGroup boss;
        if(enableEpoll){
            EpollEventLoopGroup epollBoss = new EpollEventLoopGroup(1,new ThreadFactoryX("Epoll","Server-Boss"));
//            epollBoss.setIoRatio(ioRatio);
            boss = epollBoss;
        }else {
            NioEventLoopGroup jdkBoss = new NioEventLoopGroup(1,new ThreadFactoryX("NIO","Server-Boss"));
            jdkBoss.setIoRatio(ioRatio);
            boss = jdkBoss;
        }
        return boss;
    }
 
Example 5
Source File: AbstractNettyClient.java    From spring-boot-protocol with Apache License 2.0 5 votes vote down vote up
protected EventLoopGroup newWorkerEventLoopGroup() {
        EventLoopGroup worker;
        if(enableEpoll){
            EpollEventLoopGroup epollWorker = new EpollEventLoopGroup(ioThreadCount,new ThreadFactoryX("Epoll",namePre+"Client-Worker"));
//            epollWorker.setIoRatio(ioRatio);
            worker = epollWorker;
        }else {
            NioEventLoopGroup nioWorker = new NioEventLoopGroup(ioThreadCount,new ThreadFactoryX("NIO",namePre+"Client-Worker"));
            nioWorker.setIoRatio(ioRatio);
            worker = nioWorker;
        }
        return worker;
    }
 
Example 6
Source File: Connector.java    From multi-model-server with Apache License 2.0 5 votes vote down vote up
public static EventLoopGroup newEventLoopGroup(int threads) {
    if (useNativeIo && Epoll.isAvailable()) {
        return new EpollEventLoopGroup(threads);
    } else if (useNativeIo && KQueue.isAvailable()) {
        return new KQueueEventLoopGroup(threads);
    }

    NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(threads);
    eventLoopGroup.setIoRatio(ConfigManager.getInstance().getIoRatio());
    return eventLoopGroup;
}
 
Example 7
Source File: NettyUDPConnector.java    From mpush with Apache License 2.0 5 votes vote down vote up
private void createNioServer(Listener listener) {
    NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(
            1, new DefaultThreadFactory(ThreadNames.T_GATEWAY_WORKER)
    );
    eventLoopGroup.setIoRatio(100);
    createServer(listener, eventLoopGroup, () -> new NioDatagramChannel(IPv4));//默认是根据机器情况创建Channel,如果机器支持ipv6,则无法使用ipv4的地址加入组播
}
 
Example 8
Source File: NettyTCPClient.java    From mpush with Apache License 2.0 5 votes vote down vote up
private void createNioClient(Listener listener) {
    NioEventLoopGroup workerGroup = new NioEventLoopGroup(
            getWorkThreadNum(), new DefaultThreadFactory(ThreadNames.T_TCP_CLIENT), getSelectorProvider()
    );
    workerGroup.setIoRatio(getIoRate());
    createClient(listener, workerGroup, getChannelFactory());
}