nacos连接cpu暴增

nacos连接cpu暴增

一个项目遇到一个nacos问题,经常导致cpu暴增从而死机

com.alibaba.nacos.client.Worker.fixed-10.254.108.164_88-c8adf6e3-cc0a-4ff0-a91e-854f5c670690" #46404 daemon prio=5 os_prio=0 tid=0x00007f20f005e800 nid=0x7dcc waiting on condition [0x00007f1f1d75d000]
java.lang.Thread.State: TIMED_WAITING (parking)

原因我们这里在下文继续分析,这里我们直接说明解决方法和尝试过程

第一个尝试:网上有提出是druid的版本太低导致,jar包下面的dataabstactsource的文件里的
低版本没有判断是否创建
public void setUsername(String username) {
if (this.inited) {
throw new UnsupportedOperationException();
} else {
this.username = username;
}
}

高版本
public void setUsername(String username) {
if (!StringUtils.equals(this.username, username)) {
if (this.inited) {
throw new UnsupportedOperationException();
} else {
this.username = username;
}
}
}

解决方案:这里的这个判断是不可少的! nacos 会每个30 s 就去获取配置, 然后rebind, 但是druid-1.0.26 rebind 就会报错, 报错有没有打印出来! 我擦。 druid-1.1.4 就不会有这个问题了!检查其他方法, 发现都做了 !StringUtils.equals 判断。

参考博客:https://blog.csdn.net/weixin_30783629/article/details/96637747

但是没有解决问题,博主就进行第二个的尝试,换一种方式的代码
不使用Environment 的方式连接 我们直接使用NacosConfigProperties的方式连接,这里注意配置文件需要写到bootstrap.yml中(地址和空间名)

@Autowired
private NacosConfigProperties nacosConfigProperties;

private static final String DATAID = “jservice.yml”;

private static final String GROUPID = “JMAS-JMOPEN”;

/**

  • logger
    */
    private final Log logger = LogFactory.getLog(getClass());

/**

  • 返回接口应用接口全部和地址状态

  • @return

  • @throws NacosException
    */
    public CycleConfig findStatisticalConfig() {
    CycleConfig warnConfig = new CycleConfig();
    try {
    ConfigService configService = nacosConfigProperties.configServiceInstance();
    String content = configService.getConfig(DATAID, GROUPID, 3000);
    Yaml yaml = new Yaml();
    Map configMap = (Map)yaml.load(content);

     String dingDingAddress = (String)configMap.get("dingDingAddress");
     int normalPollingCycle = (int)configMap.get("normalPollingCycle");
     int detectedPollingCycle = (int)configMap.get("detectedPollingCycle");
     int faultPollingCycle = (int)configMap.get("faultPollingCycle");
     boolean jservicestatus = (boolean)configMap.get("jservicestatus");
     boolean jmportalstatus = (boolean)configMap.get("jmportalstatus");
     String jserviceAPPurl = (String)configMap.get("jserviceAPPurl");
     String jserviceInterfaceurl = (String)configMap.get("jserviceInterfaceurl");
     String jmportalurl = (String)configMap.get("jmportalurl");
     String appUid = (String)configMap.get("appUid");
     String interfaceUid = (String)configMap.get("interfaceUid");
     warnConfig.setNormalPollingCycle(normalPollingCycle);
     warnConfig.setAppUid(appUid);
     warnConfig.setDetectedPollingCycle(detectedPollingCycle);
     warnConfig.setDingDingAddress(dingDingAddress);
     warnConfig.setFaultPollingCycle(faultPollingCycle);
     warnConfig.setInterfaceUid(interfaceUid);
     warnConfig.setJmportalurl(jmportalurl);
     warnConfig.setJserviceAPPurl(jserviceAPPurl);
     warnConfig.setJserviceInterfaceurl(jserviceInterfaceurl);
     warnConfig.setJservicestatus(jservicestatus);
     warnConfig.setNormalPollingCycle(normalPollingCycle);
    

    } catch (Exception e) {
    logger.error(e);
    }
    return warnConfig;
    }

这里的直接测试会降低出现的暴增现象,但是还是会出现线程数增多的现象

之后进行了第三次尝试,更新nacos到1.1.4中,在官方文档中对本次更新提出
Health check field and protection threshold are confused
#1409 Integrate with Istio as a service discovery backend
#1507 It is recommended that the shutdown.sh script close only the nodes in the current directory, not all nodes.
#1665 DataSync always not executed after network partition
#1671 ‘Client-Version’ header not set in http request from nacos client
#1759 The number of new configuration words is too long. Tip 400 is not friendly enough.
#1825 In modifying service instance page.Error information not clear
#1874 Repeat defined class NacoException
#1906 Set a new thread pool here, but do not open the Notifier task, whether to add executor.execute(new Notifier());

翻译为
健康检查字段和保护阈值混淆
#1409集成Istio作为服务发现后端
建议关闭.sh脚本只关闭当前目录中的节点,而不是所有节点。
#1665 DataSync总是在网络分区后不执行
客户端版本的报头没有在来自nacos客户端的http请求中设置
新组态词的数量太长了。小费400不够友好。
#1825在修改服务实例页面。错误信息不清晰
重复定义类NacoException
在这里设置一个新的线程池,但是不打开Notifier任务,是否添加executor。执行(新通知());

也就是说解决了一部分重复报错连接问题。

升级nacos
0.8.0及以上版本:

解压安装包后替换{nacos.home}/target/nacos-server.jar
删除{nacos.home}/plugins/cmdb/及{nacos.home}/plugins/health/下的所有文件
逐台重启Nacos Server即可
0.8.0以下版本,先升级到1.0.0版本。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值