Netty - EventLoop 队列监控

Netty - EventLoop Queue Monitoring

我将 Netty 服务器用于 Spring 启动应用程序。无论如何要监视 Netty 服务器队列大小,以便我们知道队列是否已满以及服务器是否无法接受任何新请求?另外,如果队列已满或无法接受新请求,netty 服务器是否有任何日志记录?

Netty 没有为此目的的任何日志记录,但我实现了一种方法来查找未决任务并根据您的问题放置一些日志。这是我本地的示例日志

你可以在这里找到所有代码https://github.com/ozkanpakdil/spring-examples/tree/master/reactive-netty-check-connection-queue

关于代码,它本身非常具有解释性,但 NettyConfigure 实际上是在 spring 引导环境中进行 netty 配置。在 https://github.com/ozkanpakdil/spring-examples/blob/master/reactive-netty-check-connection-queue/src/main/java/com/mascix/reactivenettycheckconnectionqueue/NettyConfigure.java#L46 you can see "how many pending tasks" in the queue. DiscardServerHandler may help you how to discard if the limit is full. You can use jmeter for the test here is the jmeter file https://github.com/ozkanpakdil/spring-examples/blob/master/reactive-netty-check-connection-queue/PerformanceTestPlanMemoryThread.jmx

如果你想处理网络限制,你可以像下面的代码那样做

@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    totalConnectionCount.incrementAndGet();
    if (ctx.channel().isWritable() == false) { // means we hit the max limit of netty
        System.out.println("I suggest we should restart or put a new server to our pool :)");
    }
    super.channelActive(ctx);
}

你应该检查 for handling the limits and here is another explanation about "isWritable"

还有一个额外的,我把执行器放在 http://localhost:8080/actuator/metrics/http 的地方。server.requests 也很好检查。