io.netty.channel.nio.NioEventLoopGroup.setIoRatio()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中io.netty.channel.nio.NioEventLoopGroup.setIoRatio()方法的一些代码示例,展示了NioEventLoopGroup.setIoRatio()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NioEventLoopGroup.setIoRatio()方法的具体详情如下:
包路径:io.netty.channel.nio.NioEventLoopGroup
类名称:NioEventLoopGroup
方法名:setIoRatio

NioEventLoopGroup.setIoRatio介绍

[英]Sets the percentage of the desired amount of time spent for I/O in the child event loops. The default value is 50, which means the event loop will try to spend the same amount of time for I/O as for non-I/O tasks.
[中]设置子事件循环中I/O所需时间的百分比。默认值为50,这意味着事件循环将尝试花费与非I/O任务相同的I/O时间。

代码示例

代码示例来源:origin: eclipse-vertx/vert.x

/**
 * @return a new event loop group
 */
public EventLoopGroup eventLoopGroup(int nThreads, ThreadFactory threadFactory, int ioRatio) {
 NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(nThreads, threadFactory);
 eventLoopGroup.setIoRatio(ioRatio);
 return eventLoopGroup;
}

代码示例来源:origin: mpusher/mpush

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的地址加入组播
}

代码示例来源:origin: fengjiachun/Jupiter

@Override
public void setIoRatio(int workerIoRatio) {
  EventLoopGroup worker = worker();
  if (worker instanceof EpollEventLoopGroup) {
    ((EpollEventLoopGroup) worker).setIoRatio(workerIoRatio);
  } else if (worker instanceof KQueueEventLoopGroup) {
    ((KQueueEventLoopGroup) worker).setIoRatio(workerIoRatio);
  } else if (worker instanceof NioEventLoopGroup) {
    ((NioEventLoopGroup) worker).setIoRatio(workerIoRatio);
  }
}

代码示例来源:origin: fengjiachun/Jupiter

@Override
public void setIoRatio(int workerIoRatio) {
  EventLoopGroup worker = worker();
  if (worker instanceof EpollEventLoopGroup) {
    ((EpollEventLoopGroup) worker).setIoRatio(workerIoRatio);
  } else if (worker instanceof KQueueEventLoopGroup) {
    ((KQueueEventLoopGroup) worker).setIoRatio(workerIoRatio);
  } else if (worker instanceof NioEventLoopGroup) {
    ((NioEventLoopGroup) worker).setIoRatio(workerIoRatio);
  }
}

代码示例来源:origin: fengjiachun/Jupiter

@Override
public void setIoRatio(int bossIoRatio, int workerIoRatio) {
  EventLoopGroup boss = boss();
  if (boss instanceof EpollEventLoopGroup) {
    ((EpollEventLoopGroup) boss).setIoRatio(bossIoRatio);
  } else if (boss instanceof KQueueEventLoopGroup) {
    ((KQueueEventLoopGroup) boss).setIoRatio(bossIoRatio);
  } else if (boss instanceof NioEventLoopGroup) {
    ((NioEventLoopGroup) boss).setIoRatio(bossIoRatio);
  }
  EventLoopGroup worker = worker();
  if (worker instanceof EpollEventLoopGroup) {
    ((EpollEventLoopGroup) worker).setIoRatio(workerIoRatio);
  } else if (worker instanceof KQueueEventLoopGroup) {
    ((KQueueEventLoopGroup) worker).setIoRatio(workerIoRatio);
  } else if (worker instanceof NioEventLoopGroup) {
    ((NioEventLoopGroup) worker).setIoRatio(workerIoRatio);
  }
}

代码示例来源:origin: fengjiachun/Jupiter

@Override
public void setIoRatio(int bossIoRatio, int workerIoRatio) {
  EventLoopGroup boss = boss();
  if (boss instanceof EpollEventLoopGroup) {
    ((EpollEventLoopGroup) boss).setIoRatio(bossIoRatio);
  } else if (boss instanceof KQueueEventLoopGroup) {
    ((KQueueEventLoopGroup) boss).setIoRatio(bossIoRatio);
  } else if (boss instanceof NioEventLoopGroup) {
    ((NioEventLoopGroup) boss).setIoRatio(bossIoRatio);
  }
  EventLoopGroup worker = worker();
  if (worker instanceof EpollEventLoopGroup) {
    ((EpollEventLoopGroup) worker).setIoRatio(workerIoRatio);
  } else if (worker instanceof KQueueEventLoopGroup) {
    ((KQueueEventLoopGroup) worker).setIoRatio(workerIoRatio);
  } else if (worker instanceof NioEventLoopGroup) {
    ((NioEventLoopGroup) worker).setIoRatio(workerIoRatio);
  }
}

代码示例来源:origin: mpusher/mpush

private void createNioServer(Listener listener) {
  EventLoopGroup bossGroup = getBossGroup();
  EventLoopGroup workerGroup = getWorkerGroup();
  if (bossGroup == null) {
    NioEventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(getBossThreadNum(), getBossThreadFactory(), getSelectorProvider());
    nioEventLoopGroup.setIoRatio(100);
    bossGroup = nioEventLoopGroup;
  }
  if (workerGroup == null) {
    NioEventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(getWorkThreadNum(), getWorkThreadFactory(), getSelectorProvider());
    nioEventLoopGroup.setIoRatio(getIoRate());
    workerGroup = nioEventLoopGroup;
  }
  createServer(listener, bossGroup, workerGroup, getChannelFactory());
}

代码示例来源:origin: mpusher/mpush

private void createNioClient(Listener listener) {
  NioEventLoopGroup workerGroup = new NioEventLoopGroup(
      getWorkThreadNum(), new DefaultThreadFactory(ThreadNames.T_TCP_CLIENT), getSelectorProvider()
  );
  workerGroup.setIoRatio(getIoRate());
  createClient(listener, workerGroup, getChannelFactory());
}

代码示例来源:origin: Netflix/zuul

DefaultSelectStrategyFactory.INSTANCE
);
((NioEventLoopGroup) clientToProxyWorkerPool).setIoRatio(90);

代码示例来源:origin: io.vertx/vertx-core

/**
 * @return a new event loop group
 */
public EventLoopGroup eventLoopGroup(int nThreads, ThreadFactory threadFactory, int ioRatio) {
 NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(nThreads, threadFactory);
 eventLoopGroup.setIoRatio(ioRatio);
 return eventLoopGroup;
}

代码示例来源:origin: Netflix/zuul

DefaultSelectStrategyFactory.INSTANCE
);
((NioEventLoopGroup) clientToProxyWorkerPool).setIoRatio(90);

代码示例来源:origin: linkedin/flashback

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;
}

代码示例来源:origin: org.opendaylight.openflowjava/openflow-protocol-impl

/**
 * Initiate Nio event loop groups
 * @param threadConfiguration number of threads to be created, if not specified in threadConfig
 */
public void initiateNioEventLoopGroups(ThreadConfiguration threadConfiguration) {
  socketChannelClass = NioServerSocketChannel.class;
  if (threadConfiguration != null) {
    bossGroup = new NioEventLoopGroup(threadConfiguration.getBossThreadCount());
    workerGroup = new NioEventLoopGroup(threadConfiguration.getWorkerThreadCount());
  } else {
    bossGroup = new NioEventLoopGroup();
    workerGroup = new NioEventLoopGroup();
  }
  ((NioEventLoopGroup)workerGroup).setIoRatio(100);
}

代码示例来源:origin: BazingaLyn/laopopo-rpc

@Override
public void init() {
  ThreadFactory workerFactory = new DefaultThreadFactory("netty.client");
  worker = initEventLoopGroup(nWorkers, workerFactory);
  
  bootstrap = new Bootstrap().group(worker);
  if (worker instanceof EpollEventLoopGroup) {
    ((EpollEventLoopGroup) worker).setIoRatio(100);
  } else if (worker instanceof NioEventLoopGroup) {
    ((NioEventLoopGroup) worker).setIoRatio(100);
  }
  bootstrap.option(ChannelOption.ALLOCATOR, allocator).option(ChannelOption.MESSAGE_SIZE_ESTIMATOR, DefaultMessageSizeEstimator.DEFAULT)
      .option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, (int) SECONDS.toMillis(3));
  bootstrap.option(ChannelOption.SO_KEEPALIVE, true).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.ALLOW_HALF_CLOSURE, false);
  if (writeBufferLowWaterMark >= 0 && writeBufferHighWaterMark > 0) {
    WriteBufferWaterMark waterMark = new WriteBufferWaterMark(writeBufferLowWaterMark, writeBufferHighWaterMark);
    bootstrap.option(ChannelOption.WRITE_BUFFER_WATER_MARK, waterMark);
  }
}

代码示例来源:origin: net.lightbody.bmp/littleproxy

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);
}

代码示例来源:origin: com.github.mike10004/littleproxy

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);
}

代码示例来源:origin: org.jupiter-rpc/jupiter-all

@Override
public void setIoRatio(int workerIoRatio) {
  EventLoopGroup worker = worker();
  if (worker instanceof EpollEventLoopGroup) {
    ((EpollEventLoopGroup) worker).setIoRatio(workerIoRatio);
  } else if (worker instanceof KQueueEventLoopGroup) {
    ((KQueueEventLoopGroup) worker).setIoRatio(workerIoRatio);
  } else if (worker instanceof NioEventLoopGroup) {
    ((NioEventLoopGroup) worker).setIoRatio(workerIoRatio);
  }
}

代码示例来源:origin: org.jupiter-rpc/jupiter-transport-netty

@Override
public void setIoRatio(int workerIoRatio) {
  EventLoopGroup worker = worker();
  if (worker instanceof EpollEventLoopGroup) {
    ((EpollEventLoopGroup) worker).setIoRatio(workerIoRatio);
  } else if (worker instanceof KQueueEventLoopGroup) {
    ((KQueueEventLoopGroup) worker).setIoRatio(workerIoRatio);
  } else if (worker instanceof NioEventLoopGroup) {
    ((NioEventLoopGroup) worker).setIoRatio(workerIoRatio);
  }
}

代码示例来源:origin: org.jupiter-rpc/jupiter-transport-netty

@Override
public void setIoRatio(int bossIoRatio, int workerIoRatio) {
  EventLoopGroup boss = boss();
  if (boss instanceof EpollEventLoopGroup) {
    ((EpollEventLoopGroup) boss).setIoRatio(bossIoRatio);
  } else if (boss instanceof KQueueEventLoopGroup) {
    ((KQueueEventLoopGroup) boss).setIoRatio(bossIoRatio);
  } else if (boss instanceof NioEventLoopGroup) {
    ((NioEventLoopGroup) boss).setIoRatio(bossIoRatio);
  }
  EventLoopGroup worker = worker();
  if (worker instanceof EpollEventLoopGroup) {
    ((EpollEventLoopGroup) worker).setIoRatio(workerIoRatio);
  } else if (worker instanceof KQueueEventLoopGroup) {
    ((KQueueEventLoopGroup) worker).setIoRatio(workerIoRatio);
  } else if (worker instanceof NioEventLoopGroup) {
    ((NioEventLoopGroup) worker).setIoRatio(workerIoRatio);
  }
}

代码示例来源:origin: awslabs/mxnet-model-server

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;
}

相关文章