Netty-EventLoop队列监视

问题描述

我正在将Netty服务器用于Spring引导应用程序。无论如何,有没有要监视Netty服务器队列大小的信息,以便我们知道队列是否已满并且服务器无法接受任何新请求?另外,如果队列已满或无法接受新请求,netty服务器是否会记录日志?

解决方法

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

您可以在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

如果您要处理净资产限额,可以按照以下代码进行操作

@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也很容易检查。