我尝试了以下连接和工作人员的组合
- 4 个工作人员 - 16 个连接 - 流量仅在 4 个连接中流动,而在 12 个连接中没有流量
- 8 个工作人员 - 16 个连接 - 流量仅在 8 个连接中流动,而在 8 个连接中没有流量
- 0 个工人(我只是让最佳工人数由 Netty 确定) - 8 个连接 - 流量仅在 4 个连接中流动,在 4 个连接中没有流量
我的软件使用 NioServerSocket 配置 Netty 3.2.6
管道片段
public void startServer(int numWorkerThreads, String openFlowHost, int openFlowPort, OFChannelHandler ofchan){
this.workerThreads = numWorkerThreads;
try {
final ServerBootstrap bootstrap = createServerBootStrap();
bootstrap.setOption("reuseAddr", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.receiveBufferSize", EnhancedController.RECEIVE_BUFFER_SIZE);
bootstrap.setOption("child.sendBufferSize", EnhancedController.SEND_BUFFER_SIZE);
// better to have an receive buffer predictor
//bootstrap.setOption("receiveBufferSizePredictorFactory",
// new AdaptiveReceiveBufferSizePredictorFactory());
//if the server is sending 1000 messages per sec, optimum write buffer water marks will
//prevent unnecessary throttling, Check NioSocketChannelConfig doc
//bootstrap.setOption("writeBufferLowWaterMark", WRITE_BUFFER_LOW_WATERMARK);
//bootstrap.setOption("writeBufferHighWaterMark", WRITE_BUFFER_HIGH_WATERMARK);
// TODO: IMPORTANT: If the threadpool is supplied as null, ExecutionHandler would
// not be present in pipeline. If the load increases and ordering is required ,
// use OrderedMemoryAwareThreadPoolExecutor as argument instead of null
execHandler = new OrderedMemoryAwareThreadPoolExecutor(
OMATPE_CORE_POOL_SIZE,
OMATPE_PER_CHANNEL_SIZE,
OMATPE_POOL_WIDE_SIZE,
OMATPE_THREAD_KEEP_ALIVE_IN_MILLISECONDS,
TimeUnit.MILLISECONDS);
ChannelPipelineFactory pfact =
new OpenflowPipelineFactory(controller, execHandler);
bootstrap.setPipelineFactory(pfact);
InetSocketAddress sa =
(openFlowHost == null)
? new InetSocketAddress(openFlowPort)
: new InetSocketAddress(openFlowHost, openFlowPort);
final ChannelGroup cg = new DefaultChannelGroup();
cg.add(bootstrap.bind(sa));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private ServerBootstrap createServerBootStrap() {
if (workerThreads == 0) {
return new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
} else {
return new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool(), workerThreads));
}
}
硬件配置 四核 Intel i5 vPro 和 Ubuntu 11.x
如果我遗漏了一些明显的东西,请告诉我