我将Netty服务器用于Spring引导应用程序。有没有办法监控Netty服务器的队列大小,这样我们就可以知道队列是否已满,服务器是否无法接受任何新请求?此外,如果队列已满或无法接受新请求,netty服务器是否会记录日志?
发布于 2020-11-08 05:07:52
Netty没有任何用于此目的的日志,但我实现了一种方法来查找挂起的任务,并根据您的问题放置一些日志。下面是我的本地日志示例

你可以在这里找到所有的代码https://github.com/ozkanpakdil/spring-examples/tree/master/reactive-netty-check-connection-queue
代码本身很容易解释,但NettyConfigure实际上是在spring boot环境中进行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也很好检查的地方。
https://stackoverflow.com/questions/64602986
复制相似问题