0

这是我的childhandler。一切似乎都工作正常,但是当我在大约 3 分钟后开始同时对 60 个用户和 30 个用户进行负载测试时,服务器开始拒绝我的连接。关于如何解决这个问题的任何想法?我正在使用Locust进行负载测试。

public class CspNettySocketServerInitializer extends ChannelInitializer<SocketChannel> {
    
    // ===========================================================
    // 1. define a separate thread pool to execute handlers with
    //    slow business logic. e.g database operation
    // ===========================================================
    final EventExecutorGroup group = new DefaultEventExecutorGroup(1500); //thread pool of 1500

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast("idleStateHandler", new IdleStateHandler(1, 1, 1, TimeUnit.MINUTES)); // https://netty.io/4.1/api/index.html?io/netty/handler/timeout/IdleStateHandler.html
        pipeline.addLast(new ByteArrayDecoder()); // add without name, name auto generated
        pipeline.addLast(new ByteArrayEncoder()); // add without name, name auto generated

        //===========================================================
        // 2. run handler with slow business logic 
        //    in separate thread from I/O thread
        //===========================================================
        pipeline.addLast(group, "serverHandler", new CspNettyServerHandle()); 
        //pipeline.addLast(new CspNettyServerHandle());
    }
}
4

0 回答 0