【发布时间】:2020-10-30 05:03:48
【问题描述】:
我正在将 Netty 服务器用于 Spring 引导应用程序。有没有办法监控 Netty 服务器队列大小,以便我们知道队列是否已满,服务器是否无法接受任何新请求?另外,如果队列已满或无法接受新请求,netty 服务器是否有任何日志记录?
【问题讨论】:
我正在将 Netty 服务器用于 Spring 引导应用程序。有没有办法监控 Netty 服务器队列大小,以便我们知道队列是否已满,服务器是否无法接受任何新请求?另外,如果队列已满或无法接受新请求,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 也很好检查的地方。
【讨论】: