Netty Server - 连接数与工作数

时间:2013-07-02 21:39:43

标签: java netty worker

我尝试了以下关于连接和工作人员的组合

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

硬件配置 采用Ubuntu 11.x的四核英特尔i5 vPro

如果我遗漏了一些明显的东西,请告诉我

0 个答案:

没有答案