Slow Net Performance

I use netty to download large files from the server. When performing a performance test using jmeter, I found that my server provides a very high throughput of up to 150 concurrent users, but as soon as the number of concurrent users increases, it starts to decline and becomes almost half of the 500 concurrent users.

NettyServer -

ServerBootstrap b = new ServerBootstrap();
    EpollEventLoopGroup bossGroup = new EpollEventLoopGroup();
    EpollEventLoopGroup workerGroup = new EpollEventLoopGroup();
  try {
        b.group(bossGroup, workerGroup).channel(EpollServerSocketChannel.class).handler(new LoggingHandler(LogLevel.DEBUG)).childHandler(new FileServerInitializer());
        Channel ch = b.bind(port).sync().channel();
        ch.closeFuture().sync();

    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
        FileServerHandler.threadPool.shutdownNow();
    }

FileServerInitializer -

ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    pipeline.addLast("handler", (ChannelHandler) new FileServerHandler());
}

FileServerHandler -

    RandomAccessFile raf;
    try {
        raf = new RandomAccessFile(file, "r");
    } catch (FileNotFoundException ignore) {
        sendError(ctx, HttpResponseStatus.NOT_FOUND);
        return;
    }
    response = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.OK);
    response.headers().set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + fileNameType);
    response.headers().set(HttpHeaders.CONTENT_LENGTH, String.valueOf(size));

    ctx.write(response);
    ChannelFuture sendFileFuture;
    ChannelFuture lastContentFuture;
    sendFileFuture = ctx.writeAndFlush(new HttpChunkedInput(new ChunkedFile(raf, 0, size, 8192)),ctx.newProgressivePromise());
    lastContentFuture = sendFileFuture; 
    sendFileFuture.addListener(new ChannelProgressiveFutureListener() {

        public void operationProgressed(ChannelProgressiveFuture future, long progress, long total) {
            if (total < 0) {            
                System.out.println(future.channel() + " Transfer progress: " + progress);
            }else {
                System.out.println(future.channel() + " Transfer progress: " + progress + " / " + total);
            }
        }

        public void operationComplete(ChannelProgressiveFuture future) {
            System.out.println(future.channel() + " Transfer complete.");
        }
    });

    lastContentFuture.addListener(ChannelFutureListener.CLOSE);

Can someone tell me why this is happening?

+4
source share
1 answer

You can also try:

  • change auxiliary properties on the network side, for example (get your own correct values)

    bootstrap.channel(NioServerSocketChannel.class);
    bootstrap.group(groupBoss, groupWorker);
    bootstrap.option(ChannelOption.TCP_NODELAY, true);
    bootstrap.option(ChannelOption.SO_REUSEADDR, true);
    bootstrap.option(ChannelOption.SO_LINGER, 0);
    bootstrap.childOption(ChannelOption.TCP_NODELAY, true);
    bootstrap.childOption(ChannelOption.SO_REUSEADDR, true);
    bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
    bootstrap.childOption(ChannelOption.SO_LINGER, 0);
    bootstrap.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout);
    bootstrap.childOption(ChannelOption.SO_RCVBUF, 1048576);
    bootstrap.childOption(ChannelOption.SO_SNDBUF, 1048576);
    bootstrap.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 10*65536);
    bootstrap.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 2*65536);
    bootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    
  • BOSS, WORKER ( 2N + 1, N - Boss, )

    Me 2N + 1 Boss 10N + 1 Worker ( Worker , , , "" , , - ). Linux, .

, , . .

+2

Source: https://habr.com/ru/post/1667011/


All Articles