开发者社区 > 云原生 > 正文

第一次执行com.alibaba.csp.sentinel.SphU#entry(java.lang

第一次执行com.alibaba.csp.sentinel.SphU#entry(java.lang.String)会觉得很慢

MetricTimerListener在初始化的过程中会创建一个MetricWriter对象,该类的对象里面会调用getPid()并且最终调用InetAddress.getLocalHost(),目前我这边通过调用com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager#getRules()来预先初始化MetricTimerListener,有没有更好的办法?

下面是调用栈:

"main" #1 prio=5 os_prio=31 tid=0x00007fe10080b000 nid=0x2803 runnable [0x0000700007965000] java.lang.Thread.State: RUNNABLE at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928) at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323) at java.net.InetAddress.getLocalHost(InetAddress.java:1500) - locked <0x000000076ba7bea0> (a java.lang.Object) at sun.management.VMManagementImpl.getVmId(VMManagementImpl.java:140) at sun.management.RuntimeImpl.getName(RuntimeImpl.java:59) at com.alibaba.csp.sentinel.util.PidUtil.getPid(PidUtil.java:26) at com.alibaba.csp.sentinel.node.metric.MetricWriter.(MetricWriter.java:80) at com.alibaba.csp.sentinel.node.metric.MetricTimerListener.(MetricTimerListener.java:33) at com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager.(FlowRuleManager.java:64) at com.alibaba.csp.sentinel.slots.block.flow.FlowSlot.entry(FlowSlot.java:117) at com.alibaba.csp.sentinel.slots.block.flow.FlowSlot.entry(FlowSlot.java:111) at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.transformEntry(AbstractLinkedProcessorSlot.java:40) at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.fireEntry(AbstractLinkedProcessorSlot.java:32) at com.alibaba.csp.sentinel.slots.block.authority.AuthoritySlot.entry(AuthoritySlot.java:39) at com.alibaba.csp.sentinel.slots.block.authority.AuthoritySlot.entry(AuthoritySlot.java:33) at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.transformEntry(AbstractLinkedProcessorSlot.java:40) at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.fireEntry(AbstractLinkedProcessorSlot.java:32) at com.alibaba.csp.sentinel.slots.system.SystemSlot.entry(SystemSlot.java:36) at com.alibaba.csp.sentinel.slots.system.SystemSlot.entry(SystemSlot.java:30) at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.transformEntry(AbstractLinkedProcessorSlot.java:40) at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.fireEntry(AbstractLinkedProcessorSlot.java:32) at com.alibaba.csp.sentinel.slots.statistic.StatisticSlot.entry(StatisticSlot.java:54) at com.alibaba.csp.sentinel.slots.statistic.StatisticSlot.entry(StatisticSlot.java:48) at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.transformEntry(AbstractLinkedProcessorSlot.java:40) at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.fireEntry(AbstractLinkedProcessorSlot.java:32) at com.alibaba.csp.sentinel.slots.logger.LogSlot.entry(LogSlot.java:35) at com.alibaba.csp.sentinel.slots.logger.LogSlot.entry(LogSlot.java:29) at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.transformEntry(AbstractLinkedProcessorSlot.java:40) at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.fireEntry(AbstractLinkedProcessorSlot.java:32) at com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot.entry(ClusterBuilderSlot.java:103) at com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot.entry(ClusterBuilderSlot.java:48) at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.transformEntry(AbstractLinkedProcessorSlot.java:40) at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.fireEntry(AbstractLinkedProcessorSlot.java:32) at com.alibaba.csp.sentinel.slots.nodeselector.NodeSelectorSlot.entry(NodeSelectorSlot.java:171) at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.transformEntry(AbstractLinkedProcessorSlot.java:40) at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.fireEntry(AbstractLinkedProcessorSlot.java:32) at com.alibaba.csp.sentinel.slotchain.DefaultProcessorSlotChain$1.entry(DefaultProcessorSlotChain.java:31) at com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot.transformEntry(AbstractLinkedProcessorSlot.java:40) at com.alibaba.csp.sentinel.slotchain.DefaultProcessorSlotChain.entry(DefaultProcessorSlotChain.java:75) at com.alibaba.csp.sentinel.CtSph.entry(CtSph.java:157) at com.alibaba.csp.sentinel.CtSph.entry(CtSph.java:300) at com.alibaba.csp.sentinel.SphU.entry(SphU.java:86) at retry.RetryDemo.testSphU(RetryDemo.java:71) at retry.RetryDemo.main(RetryDemo.java:53)

原提问者GitHub用户junplus

展开
收起
码字王 2023-05-19 19:22:58 139 0
1 条回答
写回答
取消 提交回答
  • 第一个com.alibaba.csp.sentinel.SphU#entry()调用将触发sentinel的初始化,这将花费一段时间。真正的初始化是在com.alibaba.csp.sentinel.Env的静态代码块中完成的,因此您可以在应用程序开始时显式触发初始化。只需调用System.out.println(环境类)或类似的东西。

    原回答者GitHub用户CarpenterLee

    2023-05-19 22:46:22
    赞同 展开评论 打赏
问答地址:

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载