我在 Java 8 / Spring 5 / Tomcat 8.5 Web 应用程序中观察到极长的运行请求(> 30 秒)。大多数请求都会正常响应。
值得注意的是,经过几天的正常运行后,长跑者的频率有所增加。
Threaddumps 显示 Unsafe.defineClass 挂起:
at sun.misc.Unsafe.defineClass(Native Method)
at sun.reflect.ClassDefiner.defineClass(ClassDefiner.java:63)
at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:399)
at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:394)
at java.security.AccessController.doPrivileged(Native Method)
at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:393)
at sun.reflect.MethodAccessorGenerator.generateMethod(MethodAccessorGenerator.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:53)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.core.annotation.AnnotationUtils.getValue(AnnotationUtils.java:1328)
at org.springframework.core.annotation.AnnotatedElementUtils$MergedAnnotationAttributesProcessor.getAdaptedValue(AnnotatedElementUtils.java:1627)
at org.springframework.core.annotation.AnnotatedElementUtils$MergedAnnotationAttributesProcessor.overrideAttributes(AnnotatedElementUtils.java:1610)
at org.springframework.core.annotation.AnnotatedElementUtils$MergedAnnotationAttributesProcessor.postProcess(AnnotatedElementUtils.java:1598)
at org.springframework.core.annotation.AnnotatedElementUtils$MergedAnnotationAttributesProcessor.postProcess(AnnotatedElementUtils.java:1515)
at org.springframework.core.annotation.AnnotatedElementUtils.searchWithFindSemantics(AnnotatedElementUtils.java:1145)
at org.springframework.core.annotation.AnnotatedElementUtils.searchWithFindSemantics(AnnotatedElementUtils.java:1066)
at org.springframework.core.annotation.AnnotatedElementUtils.searchWithFindSemantics(AnnotatedElementUtils.java:1038)
at org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotationAttributes(AnnotatedElementUtils.java:650)
at org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotation(AnnotatedElementUtils.java:726)
....
有人见过这个问题吗?
是否您使用保守的方法耗尽了元空间-XX:MaxMetaspaceSize
或者服务器上没有足够的 RAM?由于 GC 在元空间上运行,您的缓慢可能是由于它难以清理它而导致的。默认情况下,如果元空间内存达到MaxMetaspaceSize
所以这 30 秒的暂停可能是 GC。
然而还有一个更大的问题。您的代码中的内容是分配这些类,以及为什么它经常发生以填充元空间。通常,类是在启动期间创建的,之后创建的频率要低得多。也许您正在进行热部署并且ClassLoader
正在泄漏?
在 Java 8 之前的版本中,这可能是由于 GC 和 PermGen 耗尽而导致的,例如正如这个问题中所问的,它在哪里导致了 OutOfMemoryError https://stackoverflow.com/questions/16478894/tomcat-permgen-space-out-of-memory-exception-tomcat-hangs-and-stops-responding.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)