Spring启动测试-内存不足问题

发布于 2025-01-15 02:34:01 字数 1761 浏览 1 评论 0原文

我正在尝试使用 Maven 运行测试。应用程序包含junit测试和集成测试。使用以下配置:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire-plugin.version}</version>
                <configuration>
                    <junitArtifactName>junit:junit</junitArtifactName>
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <argLine>
                        -Xverify:none
                        -XX:TieredStopAtLevel=1
                        -Xms512m -Xmx768m -XX:MaxMetaspaceSize=256m -ea
                        -XX:MaxRAM=1000m
                        -Dfile.encoding=${project.build.sourceEncoding}
                        -Dspring.test.context.cache.maxSize=1
                    </argLine>
                    <excludedGroups>${env.MVN_EXCLUDED_TESTS}</excludedGroups>
                </configuration>
            </plugin>

测试在几乎所有情况下都使用通用配置和一个测试配置文件(对我来说没有什么可疑的)。

我尝试通过设置 maxSize 属性将缓存上下文的数量降低到 1。这可行,但对 OOM 问题没有影响。所以我已经捕获了堆转储,但我不知道那里发生了什么。我可以看到 35 个 org.springframework.beans.factory.support.DefaultListableBeanFactory 实例和 34 个 org.hibernate.internal.SessionFactoryImpl 实例,它们占用了大量内存(见图)。

内存分配, 怀疑 1 = DefaultListableBeanFactory

我只找到了一些关于 DefaultListableBeanFactory 此处 但我怀疑这就是问题所在。

您是否知道要检查或修改哪些内容以降低内存使用量?或者真的有内存泄漏吗?谢谢

I am trying to run tests using maven. Application contains junit tests & integration tests. Following configuration is used:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire-plugin.version}</version>
                <configuration>
                    <junitArtifactName>junit:junit</junitArtifactName>
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <argLine>
                        -Xverify:none
                        -XX:TieredStopAtLevel=1
                        -Xms512m -Xmx768m -XX:MaxMetaspaceSize=256m -ea
                        -XX:MaxRAM=1000m
                        -Dfile.encoding=${project.build.sourceEncoding}
                        -Dspring.test.context.cache.maxSize=1
                    </argLine>
                    <excludedGroups>${env.MVN_EXCLUDED_TESTS}</excludedGroups>
                </configuration>
            </plugin>

Tests uses common configuration in nearly all cases with one test profile (nothing is suspicious to me).

I have tried to lower number of cached contexts to 1 by setting maxSize property. That works, but without effect on OOM issue. So I have captured heapdump, but I have no idea whats going on there. I can see 35 instances of org.springframework.beans.factory.support.DefaultListableBeanFactory and 34 instances of org.hibernate.internal.SessionFactoryImpl which takes lots of memory (see picture).

memory allocation, suspect 1 = DefaultListableBeanFactory

I have only find something about DefaultListableBeanFactory here but I doubt that thats the problem.

Do you have any ideas what to check or modify to lower memory usage? Or is there realy any memory leak? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文