RocketMQ5.0 线上集群部署一定要注意这个OOM问题

这里是weihubeats ,觉得文章不错可以关注公众号小奏技术,文章首发。拒绝营销号,拒绝标题党

RocketMQ 版本

  • 5.1.0

背景

测试环境的RocketMQ总会在运行一段时间后,莫名其妙就挂掉,刚开始以为就是简单的内存不够导致的

因为测试环境给的资源不多,但是时间久了总需要重启也麻烦。总会影响测试环境,所以打算排查一下解决掉。

增加内存

开始的解决方式是增加内存,由原先的4g增加到8g,结果还是OOM,这里就怀疑可能是RocketMQ有bug导致的

OOM log分析

RocketMQ的OOM log默认是保存在distribution/target/rocketmq-xxx/rocketmq-xxx目录下

文件名称hs_err_pid1879893.log

这里给大家推荐一个OOM的log分析平台,目前是免费的

gceasy.io/?tdsourceta...

我们在Active Thread中看到所有的线程数有32380个线程,明显是不正常的

看样子还想继续增加,所以很明显就是RocketMQbug

那么为什么会创建如此多的FlowMonitor线程呢

问题定位

首先我们看看是哪里创建FlowMonitor这个线程的

可以看到主要是在创建AutoSwitchHAConnection对象的时候对FlowMonitor对象进行创建的,这里的FlowMonitor线程还没有启动

何时创建AutoSwitchHAConnection

跟随代码我们可以很快发现是在NIOSelector接受网络请求的时候就会创建一个AutoSwitchHAConnection

创建完AutoSwitchHAConnection会执行conn.start();

其中start就会启动flowMonitor线程

我们查看masterslave的log也能看到masterslave有大量的连接log

  • master
java 复制代码
2023-09-13 20:31:15 INFO AutoSwitchAcceptSocketService - HAService receive new connection, /192.168.1.172:56700
2023-09-13 20:31:22 INFO AutoSwitchAcceptSocketService - HAService receive new connection, /192.168.1.172:56714
2023-09-13 20:31:29 INFO AutoSwitchAcceptSocketService - HAService receive new connection, /192.168.1.172:59700
2023-09-13 20:31:36 INFO AutoSwitchAcceptSocketService - HAService receive new connection, /192.168.1.172:36956
2023-09-13 20:31:43 INFO AutoSwitchAcceptSocketService - HAService receive new connection, /192.168.1.172:36972
2023-09-13 20:31:50 INFO AutoSwitchAcceptSocketService - HAService receive new connection, /192.168.1.172:48866
2023-09-13 20:31:57 INFO AutoSwitchAcceptSocketService - HAService receive new connection, /192.168.1.172:56400
2023-09-13 20:32:04 INFO AutoSwitchAcceptSocketService - HAService receive new connection, /192.168.1.172:36922
2023-09-13 20:32:11 INFO AutoSwitchAcceptSocketService - HAService receive new connection, /192.168.1.172:36926
  • slave
java 复制代码
2023-09-14 03:17:32 INFO AutoSwitchHAClient - AutoSwitchHAClient connect to master 192.168.1.171:30922
2023-09-14 03:17:39 INFO AutoSwitchHAClient - AutoSwitchHAClient connect to master 192.168.1.171:30922
2023-09-14 03:17:46 INFO AutoSwitchHAClient - AutoSwitchHAClient connect to master 192.168.1.171:30922
2023-09-14 03:17:53 INFO AutoSwitchHAClient - AutoSwitchHAClient connect to master 192.168.1.171:30922
2023-09-14 03:18:00 INFO AutoSwitchHAClient - AutoSwitchHAClient connect to master 192.168.1.171:30922
2023-09-14 03:18:07 INFO AutoSwitchHAClient - AutoSwitchHAClient connect to master 192.168.1.171:30922
2023-09-14 03:18:14 INFO AutoSwitchHAClient - AutoSwitchHAClient connect to master 192.168.1.171:30922

修复问题

可以看到主要是主从连接断开后没有销毁flowMonitor线程。所以我们修改下NIO的连接关闭代码即可

相关代码可以查看这个pr

总结

目前来看5.1.0之前的版本可能都有这个问题。所以大家在实际使用的时候一定要注意自己的RocketMQ这个bug是否修复了.

不过影响说大不大,说小不小。因为masterslave频繁建立连接本身也有问题

相关推荐
nbwenren1 小时前
Springboot中SLF4J详解
java·spring boot·后端
helx822 小时前
SpringBoot中自定义Starter
java·spring boot·后端
rleS IONS3 小时前
SpringBoot获取bean的几种方式
java·spring boot·后端
lifewange3 小时前
Go语言-开源编程语言
开发语言·后端·golang
白毛大侠3 小时前
深入理解 Go:用户态和内核态
开发语言·后端·golang
王码码20354 小时前
Go语言中的数据库操作:从sqlx到ORM
后端·golang·go·接口
星辰_mya5 小时前
雪花算法和时区的关系
数据库·后端·面试·架构师
计算机学姐6 小时前
基于SpringBoot的兴趣家教平台系统
java·spring boot·后端·spring·信息可视化·tomcat·intellij-idea
總鑽風6 小时前
单点登录springcloud+mysql
后端·spring·spring cloud
0xDevNull6 小时前
Java 11 新特性概览与实战教程
java·开发语言·后端