spring-boot - 使用 apache camel 和 groovy 非堆内存的 Spring-boot 不断增加
问题描述
我们有一个 Spring Boot 应用程序,它有一个用于第三方集成的 API。对于第三方集成,我们使用 apache camel 和 groovy 作为脚本语言。我们将 producerTemplate 用于基于骆驼和 XML 的骆驼和路由上下文。在路由上下文中,我们使用 groovy 进行一些操作。
但是运行几天后,我们注意到非堆内存不断增加。 这是非堆内存使用的快照
然后我们对那个进程进行了内存相关的统计,发现有很多groovy/lang/GroovyClassLoader@0x0000000100a32e10。他们有的活着,有的死了。有成千上万的人。
class_loader classes bytes parent_loader alive? type
<bootstrap> 3417 5835717 null live <internal>
0x0000000081b805b8 1 1471 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000082d2ced0 15 40146 0x0000000082d2cf48 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x0000000082c3d2c0 1 1474 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000082d3d6d0 13 35357 0x0000000082d3d748 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x0000000083158b10 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x00000000800cd800 120 316382 0x00000000800cd860 live sun/misc/Launcher$AppClassLoader@0x000000010000f6a0
0x00000000833c5330 14 68990 null live org/codehaus/groovy/runtime/callsite/CallSiteClassLoader@0x0000000100a42750
0x0000000081f5e5f8 1 1471 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000082ff86f0 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000082fbeae8 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x00000000833c3b28 1 1471 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000830f1f18 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000081e141c8 1 1474 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000082c3aee8 1 1474 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000833b6b10 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x00000000830e9b20 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x00000000ea687a58 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000080d928e8 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000083239b10 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x00000000833b4f08 11 26125 0x00000000833b4f80 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x0000000083348300 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x00000000816dfd58 1 1471 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000830f2f38 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000082c39ef8 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000833c2700 1 1485 0x0000000082d2af08 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000816df150 1 1471 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000080d91498 1 1473 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000082d3c690 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000082d49a90 12 34183 0x0000000082d49b08 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x0000000083345b70 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x00000000833c2f78 1 1471 0x00000000833b8628 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000082fbdab0 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x00000000833b3f70 11 25942 0x00000000833b3fe8 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x0000000082ef0ea0 1 1474 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x000000008309d758 11 26153 0x000000008309d7d0 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x0000000082fbaaa8 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000082fb9a88 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000082fbce88 10 25290 0x0000000082fbcf00 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x00000000830deb78 10 25302 0x00000000830debf0 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x00000000830eab78 17 55775 0x00000000830eabf0 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x000000008308b770 13 34835 0x000000008308b7e8 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x0000000082d35ea8 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000081b429c8 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000833c3f40 1 1471 0x00000000833b3f70 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000833c5b40 1 880 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000082eee290 1 1471 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000830f4f70 11 26125 0x00000000830f4fe8 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x00000000833c43b8 1 1471 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000833c57b8 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000830ecb88 11 26110 0x00000000830ecc00 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x0000000082ff8678 11 26153 0x0000000082ff86f0 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x000000008300eb88 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000083389fb0 11 26125 0x000000008338a028 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x0000000080d92050 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000082fbea70 10 25290 0x0000000082fbeae8 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x00000000830f3f80 12 34459 0x00000000830f3ff8 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x00000000833c33a8 1 1471 0x000000008334acb8 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000081b7fd20 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000816dc5f0 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000081b42518 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000833c6790 1 1473 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000081b80108 1 1474 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000080d91c68 1 880 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x000000008299be28 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000081b42900 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000083079fb0 11 25942 0x000000008307a028 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x00000000833b4f80 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000082eeda50 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x000000008299b658 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000831ae3d8 11 26110 0x00000000831ae450 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x0000000082fbda38 10 25290 0x0000000082fbdab0 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x0000000081f5e530 1 1471 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000830ebbc8 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000081b80970 1 878 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000082d34618 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000082d3c618 10 25290 0x0000000082d3c690 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x0000000082fbaa30 11 26153 0x0000000082fbaaa8 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x00000000833c3bf0 1 880 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000833b3fe8 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000082eede38 1 892 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000830edbd8 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x000000008299ba40 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x000000008309d7d0 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x000000008308b7e8 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000080d92438 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000081e14100 1 1474 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000082d35e30 10 25292 0x0000000082d35ea8 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x00000000816df588 1 1497 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000830f4fe8 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000082fb9a10 11 26153 0x0000000082fb9a88 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x00000000ea686a98 11 26153 0x00000000ea686b10 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x00000000833c4bc8 15 72430 0x00000000800cc640 live org/codehaus/groovy/runtime/callsite/CallSiteClassLoader@0x0000000100a42750
0x00000000830f3ff8 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x000000008300eff8 1 880 null dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000ea683290 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x00000000804938b0 0 0 0x00000000800cd800 live java/util/ResourceBundle$RBClassLoader@0x000000010005ef58
0x0000000080d92820 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000831b07e0 14 32627 0x00000000831b0858 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x000000008323abd8 11 26110 0x000000008323ac50 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x000000008334bbc8 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x00000000830debf0 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000082d39380 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000082d3f780 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x00000000830dfe58 11 25944 0x00000000830dfed0 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x0000000083116a48 11 26153 0x0000000083116ac0 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x00000000831af640 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x00000000833c3a60 1 1471 0x00000000831750f8 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000833c5258 12 67191 null live org/codehaus/groovy/runtime/callsite/CallSiteClassLoader@0x0000000100a42750
0x00000000830e9aa8 10 25290 0x00000000830e9b20 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x00000000829f5738 0 0 0x00000000800cc640 live groovy/text/markup/MarkupTemplateEngine$TemplateGroovyClassLoader@0x0000000100a332a8
0x00000000830f1ea0 11 26110 0x00000000830f1f18 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x000000008309b6b8 0 0 0x00000000800cc640 live groovy/lang/GroovyClassLoader@0x0000000100a32e10
0x0000000082c3d770 1 1474 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000833c5e88 1 1471 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000082eee358 1 881 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000080d91560 1 1473 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x000000008299b720 1 880 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x0000000083239a98 14 32627 0x0000000083239b10 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x0000000083348288 11 26110 0x0000000083348300 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x0000000082d5fb68 16 49041 0x0000000082d5fbe0 live groovy/lang/GroovyClassLoader$InnerLoader@0x0000000100ba9e58
0x000000008300eac0 1 881 0x00000000800cc640 dead sun/reflect/DelegatingClassLoader@0x0000000100009df8
................................................................................................................................
................................................................................................................................
................................................................................................................................
**total = 13675 90164 204988152 N/A alive=1, dead=13674 N/A**
运行几天后,非堆内存使用量超过 1 GB,应用程序挂起且无法响应。然后我们重新启动应用程序,这种现象再次出现。
非堆内存使用率如此之高的原因可能是什么?还有什么可以缓解的吗?
更新:
在骆驼的 build.gradle 文件中添加了依赖项:
compile("org.apache.camel:camel-spring-boot-starter:2.21.2")
compile("org.apache.camel:camel-script:2.21.2")
compile("org.apache.camel:camel-groovy:2.21.2")
compile("org.apache.camel:camel-xstream:2.21.2")
compile("org.apache.camel:camel-jackson:2.21.2")
compile("org.apache.camel:camel-jdbc:2.21.2")
compile("org.apache.camel:camel-jpa:2.21.2")
compile("org.apache.camel:camel-http:2.21.2")
在我们的应用程序启动时,spring boot 会导入 camel_config.xml 文件。
@ImportResource(locations = "../camel_config.xml}")
骆驼配置上下文的内容:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<import resource="classpath:../ref_route.xml"/>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<propertyPlaceholder
id="properties"
location="classpath:application.properties"/>
<routeContextRef ref="ref_route"/>
</camelContext>
从服务层调用骆驼:
LinkedHashMap<String, String> response = producerTemplate.requestBodyAndHeaders("direct:ref_route", body, headers, LinkedHashMap.class);
骆驼路线上下文文件:ref_route.xml
解决方案
推荐阅读
- java - RuntimeException 类型不匹配。使用 phoenix JDBC 为空的布尔值
- php - 为什么我的 register_shutdown_function() 不能使用命名空间?
- ios - iOS - 如何使用泛型在 Swift 中编写 DecodeHelper 类?
- jquery - 扩展 jQuery 表格搜索脚本
- spring - Eclipse STS 使用子项目在本地运行 Spring Boot
- django - 使用 Stripe 的 Django ACH 的基本问题
- mysql - mysqld 服务无法启动
- sql - SQL Server 窗口函数基于时间的数据
- html - 悬停影响除被悬停的项目以外的其他元素
- go - 如何使用 paho.mqtt.golang 库订阅多个 MQTT 主题?