当前位置:网站首页>JVM-SANDBOX导致目标服务JVM Metaspace OOM的调查始末
JVM-SANDBOX导致目标服务JVM Metaspace OOM的调查始末
2022-07-16 21:12:00 【InfoQ】
背景
注入流程

排查过程
日志表现


Metaspace
Metaspace is a native (as in: off-heap) memory manager in the hotspot.
It is used to manage memory for class metadata. Class metadata are allocated when classes are loaded. Their lifetime is usually scoped to that of the loading classloader - when a loader gets collected, all class metadata it accumulated are released in bulk.
- 方法区迁移到Java Metaspace中
- 字符串常量池则由永久代迁移到了Java Heap中
- -XX:MetaspaceSize 是分配给类元数据空间(以字节计)的初始大小(Oracle逻辑存储上的初始高水位,the initial high-water-mark ),此值为估计值。MetaspaceSize的值设置的过大会延长垃圾回收时间。垃圾回收过后,引起下一次垃圾回收的类元数据空间的大小可能会变大。
- -XX:MaxMetaspaceSize 是分配给类元数据空间的最大值,超过此值就会触发Full GC,此值默认没有限制,但应取决于系统内存的大小。JVM会动态地改变此值。
- -XX:MinMetaspaceFreeRatio 表示一次GC以后,为了避免增加元数据空间的大小,空闲的类元数据的容量的最小比例,不够就会导致垃圾回收。
- -XX:MaxMetaspaceFreeRatio 表示一次GC以后,为了避免增加元数据空间的大小,空闲的类元数据的容量的最大比例,不够就会导致垃圾回收。
分析原因
- 第一直观感受是这个流程没毛病呀,会不会是因为业务服务JVM的Metaspace空间设置的太小?
- Metaspace的GC 没有触发或者是有泄露导致类的元数据回收不掉?

尝试解决
本地复现
参数设置


首次注入
./sandbox.sh -p 19264 -d 'broken-clock-tinker/repairCheckState'

故障清除
./sandbox.sh -p 19264 -S

多次注入&清除


问题排查
ClassLoader 关闭失败
How to Close a URLClassLoader?
The URLClassLoader close() method effectively eliminates the problem of how to support updated implementations of the classes and resources loaded from a particular codebase, and in particular from JAR files. In principle, once the application clears all references to a loader object, the garbage collector and finalization mechanisms will eventually ensure that all resources (such as the JarFile objects) are released and closed.验证猜想

EventProcessor
final ThreadLocal<Process> processRef = new ThreadLocal<Process>() {
@Override
protected Process initialValue() {
return new Process();
}
};- 假如在执行注入故障的过程中,进行故障清除会导致泄漏。如下:

- 假设使用了jvm-sandbox的特性-流程变更(例如立即返回,立即抛出异常),本质也是thread local没有及时remove,导致造成了泄漏
SandboxProtector
/**
* 判断当前是否处于守护区域中
*
* @return TRUE:在守护区域中;FALSE:非守护区域中
*/
public boolean isInProtecting() {
return isInProtectingThreadLocal.get().get() > 0;
}改进验证
多次注入&清除



总结
边栏推荐
- Quickly build an e-commerce platform based on Amazon cloud technology server free service - Deployment
- ADB common entry instructions
- Please check that you have a list of Alibaba pioneer open source projects
- ADB常用入门指令
- 如何设置三线表线条的粗细
- Leetcode -- intersection of two arrays 2
- Instance Noise A trick for stabilising GAN training
- 作为一款时序数据库,TDengine 是如何实现并开源其分布式集群功能?
- [remote desktop] rustdesk open source remote desktop, a substitute for TeamViewer and sunflower
- 「接口自动化」软件测试涨薪核心技能、让薪资涨幅200%
猜你喜欢

C # network application programming, Experiment 4: thread management exercise

Error: the solution of diamond operator is not supported in -source 1.6

(pytorch advanced road III) conv2d

Leetcode -- intersection of two arrays 2

【图片编辑小软件】FastStone Photo Resizer支持批量转换和批量重命名

Comparative investigation of three commonly used time series databases - incluxdb, Prometheus, iotdb

ROS create workspace process

20220714 adapt openharmony-v3.1-beta to aio-3568j (compile builderoot)

开发到底要不要转行软件测试?一篇足以 最全方位分析

学习记录:FSMC—扩展外部SRAM
随机推荐
SQL Server 各种锁 NOLOCK、UPDLOCK、HOLDLOCK、READPAST
Parker Parker plunger pump pv140r1k1t1nmmc
Quickly build an e-commerce platform based on Amazon cloud technology server free service - Deployment
ZVS电路初步测试
[decision tree] use decision tree to diagnose breast cancer
Raspberry pie uses opencv for image tracking, face recognition, etc
Bigdata operation week 14 & 15
(pytorch advanced road IV) vision transformer
【无标题】
自定义Hook 和 普通函数、函数组件 的区别
Why is SaaS so important for enterprise digital transformation?
ASP. Net printing industry printing management system, source code free sharing
(pytorch advanced way II) transformer learning and difficult code implementation
【远程桌面】rustdesk开源的远程桌面,TeamViewer 和向日葵的替代品
C # network application programming, experiment 1: WPF exercise
C # network application programming, experiment 7: asynchronous programming practice
[NOIP2006普及组]明明的随机数
个人做海外社交媒体还有前景吗?有好的建议吗?
20220715 domestic CONDA does not FQ the method of installing the latest version of pytoch
Enjoy yourself (VIII) Jenkins learning (to be updated)