首页 > 解决方案 > Netty - EventLoop 队列监控

问题描述

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

标签: spring-bootreactor-netty

解决方案


Netty 没有为此目的的任何日志记录,但我实现了一种查找待处理任务并根据您的问题放置一些日志的方法。这是我本地的示例日志 网络春季伐木

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

关于代码本身非常解释,但 NettyConfigure 实际上是在 spring boot env 中进行 netty 配置。在https://github.com/ozkanpakdil/spring-examples/blob/master/reactive-netty-check-connection-queue/src/main/java/com/mascix/reactivenettycheckconnectionqueue/NettyConfigure.java#L46你可以看到“队列中有多少待处理的任务”。如果限制已满,DiscardServerHandler 可能会帮助您如何丢弃。您可以使用 jmeter 进行测试,这里是 jmeter 文件https://github.com/ozkanpakdil/spring-examples/blob/master/reactive-netty-check-connection-queue/PerformanceTestPlanMemoryThread.jmx

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

@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);
}

您应该检查https://stackoverflow.com/a/49823055/175554以处理限制,这是关于“isWritable”的另一种解释https://stackoverflow.com/a/44564482/175554

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


推荐阅读