HttpRequest和LastHttpContent之间的时间过长

HttpRequest和LastHttpContent之间的时间过长,http,netty,Http,Netty,我是netty的新手,我正在尝试构建一个HTTP服务器,用于侦听来自单个客户端的传入数据。HTTP请求大约是200Kb,我们得到大约10/秒 我的问题是响应这些请求的延迟非常高(将近8秒),一些请求完全超时,我的AWS负载平衡器显示5XX响应 下面是我的设置,以及延迟为何如此之高的想法。通过查看wireshark跟踪,我可以看到请求的TCP段相距很远 服务器 public void run() { EventLoopGroup bossGroup = new NioEventLoopGr

我是netty的新手,我正在尝试构建一个HTTP服务器,用于侦听来自单个客户端的传入数据。HTTP请求大约是200Kb,我们得到大约10/秒

我的问题是响应这些请求的延迟非常高(将近8秒),一些请求完全超时,我的AWS负载平衡器显示5XX响应

下面是我的设置,以及延迟为何如此之高的想法。通过查看wireshark跟踪,我可以看到请求的TCP段相距很远

服务器

public void run() {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch)
                            throws Exception {

                        ChannelPipeline p = ch.pipeline();
                        p.addLast(new HttpRequestDecoder());
                        p.addLast(new HttpResponseEncoder());
                        p.addLast(new FacebookHttpServerHandler());
                    }

                }).option(ChannelOption.SO_KEEPALIVE, true)
                .option(ChannelOption.TCP_NODELAY, true)
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000)
                .option(ChannelOption.SO_TIMEOUT, 100)
                .option(ChannelOption.SO_BACKLOG, 1024);

        // Bind and start to accept incoming connections.
        ChannelFuture f = b.bind(port).sync();

        log.info("before shutdown server...");

        // Wait until the server socket is closed.
        // shut down your server.
        f.channel().closeFuture().sync();
    } catch (Exception e) {
        log.error("unexpected exception", e);
    }

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            log.info("shutdown gracefully...");
            workerGroup.shutdownGracefully();
            bossGroup.shutdownGracefully();
        }
    });
}

public static void main(String[] args) throws Exception {
    String host = "localhost";
    int port;
    if (args.length > 0) {
        host = args[0];
        port = Integer.parseInt(args[1]);
    } else {
        port = 8080;
    }

    log.info("host :" + host + " ,  port : " + port);
    new FacebookCollector(host, port).run();
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
    if (msg instanceof HttpRequest) {
        HttpRequest request = this.request = (HttpRequest) msg;

        if (HttpUtil.is100ContinueExpected(request)) {
            send100Continue(ctx);
        }
    }

    if (msg instanceof HttpContent) {
        HttpContent httpContent = (HttpContent) msg;

        ByteBuf content = httpContent.content();
        if (content.isReadable()) {
            buf.append(content.toString(CharsetUtil.UTF_8));
            // TODO appendDecoderResult(buf, request);
        }

        if (msg instanceof LastHttpContent) {
            LastHttpContent trailer = (LastHttpContent) msg;

            processFeed(buf.toString());

            if (!writeResponse(trailer, ctx)) {
                // If keep-alive is off, close the connection once the
                // content is fully written.
                ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(
                        ChannelFutureListener.CLOSE);
            }
        }
    }
}

非常感谢

您可以将
TCP\u NODELAY
设置为false,因为它允许网络堆栈组合多个响应。但是我们需要看到更多的代码,然后才能解决这个问题。还有什么代码会有帮助?