Lot of UDP requests lost in UDP server with Netty

前端 未结 1 1102
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-09 20:21

I wrote a simple UDP Server with Netty that simply prints out in logs the messages (frames) received. To do that, I created a simple frame decoder decoder and a simple message h

1条回答
  •  情深已故
    2021-02-09 21:14

    You have not properly configured the ConnectionlessBootstrap instance.

    1. You have to configure followings with optimum values.

      SO_SNDBUF size, SO_RCVBUF size and a ReceiveBufferSizePredictorFactory

      lBootstrap.setOption("sendBufferSize", 1048576);
      
      lBootstrap.setOption("receiveBufferSize", 1048576);
      
      lBootstrap.setOption("receiveBufferSizePredictorFactory", 
       new AdaptiveReceiveBufferSizePredictorFactory(MIN_SIZE, INITIAL_SIZE, MAX_SIZE));
      

      check DefaultNioDatagramChannelConfig class for more details.

    2. The pipeline is doing everything using the Netty work thread. If worker thread is overloaded, it will delay the selector event loop execution and there will be a bottleneck in reading/writing the channel. You have to add a execution handler as following in the pipeline. It will free the worker thread to do its own work.

      ChannelPipeline lChannelPipeline = Channels.pipeline();
      
      lChannelPipeline.addFirst("execution-handler", new ExecutionHandler(
        new OrderedMemoryAwareThreadPoolExecutor(16, 1048576, 1048576));
      
      //add rest of the handlers here
      

    0 讨论(0)
提交回复
热议问题