简体   繁体   English

Maven 在 Docker 上构建和测试非常慢

[英]Maven build and tests very slow on Docker

I'm trying setup my Gitlab CI/CD to compile and run tests for my Java/Maven/Spring Boot application.我正在尝试设置我的 Gitlab CI/CD 来为我的 Java/Maven/Spring Boot 应用程序编译和运行测试。 I've setup a Gitlab Runner and created my.gitlab-ci.yml and it all worked, but VERY SLOW.我已经设置了 Gitlab Runner 并创建了 my.gitlab-ci.yml 并且一切正常,但是非常慢。 I've tried many configurations for my runner, without success.我为我的跑步者尝试了许多配置,但没有成功。

So i made a step back and tried to run the tests on Docker on my local machine.所以我退后一步,尝试在我的本地机器上对 Docker 运行测试。

The build + tests running directly on my machine takes 17min.直接在我的机器上运行的构建 + 测试需要 17 分钟。 The build + tests running on docker takes more than 1h.在 docker 上运行的构建 + 测试需要超过 1 小时。

The best performance i've got was using using this docker command:我得到的最佳性能是使用这个 docker 命令:

docker run -it --rm --name comp2 --mount type=bind,source="C:/ProjetosJava/eaud",destination=/usr/src/mymaven -e MAVEN_OPTS='-Xdebug -Xnoagent -Djava.compiler=NONE -Xmx4096m -Xms1024m -XX:MaxPermSize=1024m -Dmaven.repo.local=.m2/repository -XX:+TieredCompilation -XX:TieredStopAtLevel=1' -w /usr/src/mymaven maven:3.3-jdk-8 /bin/bash

and inside bash i did:在 bash 里面我做了:

mvn -s.m2/settings.xml clean compile test

I need the build inside docker to have at minimun a close time (17min).我需要在 docker 内部构建,以便在最短的时间内(17 分钟)。

Found out the problem, it was the Maven Surefire plugin.发现问题,是Maven Surefire插件。

By default, surefire will fork the JVM, and when it do that it doesn't inherit the JAVA_OPTS from the mvn command.默认情况下,surefire 将分叉 JVM,并且当它这样做时,它不会从 mvn 命令继承 JAVA_OPTS。

So, i was i able to reduce the time of the build by configuring these configurations to the plugin:所以,我能够通过将这些配置配置到插件来减少构建时间:

             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration>
                    <systemPropertyVariables>
                        <java.awt.headless>true</java.awt.headless>
                    </systemPropertyVariables>
                    <argLine>-Xms256m -Xmx1024m -XX:MaxPermSize=512m -Xverify:none -XX:TieredStopAtLevel=1 -XX:-TieredCompilation</argLine>
                    <printSummary>false</printSummary>
                    <forkCount>0</forkCount>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit47</artifactId>
                        <version>3.0.0-M5</version>
                    </dependency>
                </dependencies>
            </plugin>

The secret is: argLine with -Xverify:none -XX:TieredStopAtLevel=1 -XX:-TieredCompilation and forkCount=0 .秘密是: argLine 与-Xverify:none -XX:TieredStopAtLevel=1 -XX:-TieredCompilationforkCount=0

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

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