[英]Quarkus native executable build: high memory consumption
I'm building a Quarkus native executable with a multi-stage Docker build as described in Quarkus - Building a Native Executable我正在构建一个带有多阶段 Docker 构建的 Quarkus 本机可执行文件,如Quarkus - Building a Native Executable 中所述
My project just includes the Hello World
-Example with some added ORM-functionality (so not really a lot of dependencies).我的项目只包括Hello World
-Example 和一些添加的 ORM 功能(所以并不是很多依赖项)。 The build works fine, but my problem is, that it consumes a lot of memory during build time.构建工作正常,但我的问题是,它在构建期间消耗了大量内存。 That means up to 6 GiB
.这意味着最多6 GiB
。 Build time is also very long in my opinion (~4-6 minutes in total).我认为构建时间也很长(总共约 4-6 分钟)。
The problem starts when I'm building on our CI/CD-infrastructure.当我在我们的 CI/CD 基础设施上构建时,问题就开始了。 We don't have that much memory there and so the build fails with Error: Image build request failed with exit status 137
.我们那里没有那么多内存,因此构建失败并显示Error: Image build request failed with exit status 137
。
Am I doing something wrong or is this just the normal behaviour?我做错了什么还是这只是正常行为? Is there a possibility to reduce at least the memory consumption?有没有可能至少减少内存消耗?
Thanks to Ken and Luca Burgazzoli!感谢 Ken 和 Luca Burgazzoli! So, it is normal for GraalVM to use >4GiB of RAM and to take more than 3 minutes.因此,GraalVM 使用 >4GiB 的 RAM 并花费超过 3 分钟是正常的。
One can limit memory consumption by specifiying -J-Xmx2G
as an additionalBuildArgs
-param for the quarkus-maven-plugin
.可以通过将-J-Xmx2G
指定为quarkus-maven-plugin
的additionalBuildArgs
BuildArgs -param 来限制内存消耗。 But this may increase build time.但这可能会增加构建时间。
@ben answer is correct but maybe it is useful to be more precise. @ben 的答案是正确的,但也许更准确一些很有用。 You have to edit the pom.xml
in the getting-started
dir and edit the native
profile
and adding <additionalBuildArgs>-J-Xmx2G</additionalBuildArgs>
like this:您必须在getting-started
目录中编辑pom.xml
并编辑本native
profile
并添加<additionalBuildArgs>-J-Xmx2G</additionalBuildArgs>
如下所示:
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<configuration>
<enableHttpUrlHandler>true</enableHttpUrlHandler>
<additionalBuildArgs>-J-Xmx2G</additionalBuildArgs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
...
</plugin>
</plugins>
</build>
</profile>
Now, you can limit memory usage from Quarkus:现在,您可以从 Quarkus 限制内存使用:
In your src/main/resources/application.properties file, just set:在您的 src/main/resources/application.properties 文件中,只需设置:
quarkus.native.native-image-xmx=2G
Or just pass this option to maven:或者只是将此选项传递给 maven:
mvn package -Dnative -Dquarkus.native.native-image-xmx=2G
If you are using gradle, edit the build.gradle
like this:如果您使用的是 gradle, build.gradle
像这样编辑build.gradle
:
.
.
.
compileJava {
options.compilerArgs << '-parameters'
}
buildNative {
additionalBuildArgs = [
'-J-Xmx2G'
]
}
So you can limit the memory usage when building with gradle.因此,您可以在使用 gradle 构建时限制内存使用量。
With camel quarkus example using maven, I configured as follows to make it work:使用maven的camel quarkus示例,我配置如下以使其工作:
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<quarkus.package.type>native</quarkus.package.type>
<quarkus.native.additional-build-args>-J-Xmx5G</quarkus.native.additional-build-args>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Using the option <quarkus.native.additional-build-args>-J-Xmx5G</quarkus.native.additional-build-args>
使用选项<quarkus.native.additional-build-args>-J-Xmx5G</quarkus.native.additional-build-args>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.