spring-boot - Netty - EventLoop 队列监控
问题描述
我正在将 Netty 服务器用于 Spring Boot 应用程序。有没有办法监控 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 也很好检查的地方。
推荐阅读
- angular - 使用 Angular Material 处理服务器端错误
- angular - 保持服务返回Angular 8
- sql - 如何在 Oracle 中将一个用户复制或克隆到另一个用户
- pug - 如何在 img(src="") 中为图像添加外部链接?
- python - 如何在 Python 中将 3 个箱线图组合到一张图中?
- java - android.overridePathCheck=true' 是实验性的,在 3.6 上不受支持我该怎么办?
- django - Django - 错误消息:IndentationError: unindent 不匹配任何外部缩进级别
- java - 如何创建 javafx 对话框来更新值?
- python - 奇怪的行为。创建新列时,在 Pandas 数据框中生成单个负值
- java - Java 二维数组:Java 中 A 和 B 字母的矩形