简体   繁体   English

如何调查 jenkins 中的 Java 堆空间错误

[英]How to investigate Java Heap Space errors in jenkins

I have a matrix pipeline job which performs multiple stages (something like ~200) most of which are functional tests whose results are recorded by the following code:我有一个矩阵管道作业,它执行多个阶段(大约 200 个阶段),其中大部分是功能测试,其结果由以下代码记录:

        stage('Report') {
            script {
               def summary = junit allowEmptyResults: true, testResults: "**/artifacts/${product}/test-reports/*.xml"
               def buildURL = "${env.BUILD_URL}"
               def TestAnalyzer = buildURL.replace("/${env.BUILD_NUMBER}", "/test_results_analyzer")
               def TestsURL = buildURL.replace("job/${env.JOB_NAME}/${env.BUILD_NUMBER}", "blue/organizations/jenkins/${env.JOB_NAME}/detail/${env.JOB_NAME}/${env.BUILD_NUMBER}/tests")
               slackSend (
                  color: summary.failCount == 0 ? 'good' : 'warning',
                  message: "*<${TestsURL}|Test Summary>* for *${env.JOB_NAME}* on *${env.HOSTNAME} - ${product}* <${env.BUILD_URL}| #${env.BUILD_NUMBER}> - <${TestAnalyzer}|${summary.totalCount} Tests>, Failed: ${summary.failCount}, Skipped: ${summary.skipCount}, Passed: ${summary.passCount}"
               )
            }
        }

The problem is that this Report stage regularly fails with the following error:问题是这个 Report 阶段经常失败并出现以下错误:

> Archive JUnit-formatted test results                        9m 25s
[2022-11-16T02:51:49.569Z] Recording test results
Java heap space

I have increased the heap space of the jenkins server to 8GB by modifying the systemd service configuration this way:我通过这样修改 systemd 服务配置,将 jenkins 服务器的堆空间增加到 8GB:

software-dev@magnet:~$ sudo cat /etc/systemd/system/jenkins.service.d/override.conf
[Service]
Environment="JAVA_OPTS=-Djava.awt.headless=true -Xmx8g"

which was taken into account, because I verified with the following command:考虑到了这一点,因为我使用以下命令进行了验证:

software-dev@magnet:~$ tr '\0' '\n' < /proc/$(pidof java)/cmdline
/usr/bin/java
-Djava.awt.headless=true
-Xmx10g
-jar
/usr/share/java/jenkins.war
--webroot=/var/cache/jenkins/war
--httpPort=8080

I just increased the Heap size to 10GB and I'll wait for the result of this night's build, but I have the feeling that this amount of Heap space really looks excessive, so I'm suspecting that a plugin, maybe the JUnit one, may be buggy and could consume too much memory.我刚刚将 Heap 大小增加到 10GB,我将等待今晚构建的结果,但我感觉这个 Heap 空间量看起来确实过大,所以我怀疑是一个插件,也许是 JUnit 那个,可能是越野车,可能会消耗太多 memory。

Is anyone aware of such a thing?有人知道这样的事情吗? Could there be workarounds?可以有解决方法吗?

More importantly, which methods could I use to try to track if one plugin is consuming too much?更重要的是,我可以使用哪些方法来尝试跟踪某个插件是否消耗过多? I have notions of Java since my CS degree, but I'm not familiar with the jenkins development ecosystem.自从我获得 CS 学位以来,我就有 Java 的概念,但我不熟悉 jenkins 开发生态系统。

Thank you by advance.提前谢谢你。

You can try splitting the tests into chunks/batch/groups but this solution requires changes in the code.您可以尝试将测试分成块/批/组,但此解决方案需要更改代码。

More details更多细节

https://semaphoreci.com/community/tutorials/how-to-split-junit-tests-in-a-continuous-integration-environment https://semaphoreci.com/community/tutorials/how-to-split-junit-tests-in-a-continuous-integration-environment

Grouping JUnit tests 分组 JUnit 测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM