quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.44k stars 2.58k forks source link

Native compile leading to large file and more memory footprint #41802

Open clockworkmay opened 3 weeks ago

clockworkmay commented 3 weeks ago

Describe the bug

Hello, sorry, I am pretty new to web development, so I apologize if this is a basic question. I am trying to build a Quarkus tutorial into native container as I saw that it would lead to less memory usage so I can deploy it on a smaller VM (currently targeting fly.io's free tier) after working through guides such as https://www.codecentric.de/wissens-hub/blog/spring-boot-flyio and https://www.freecodecamp.org/news/get-started-with-quarkus-and-jpastreamer-2/

However, playing with native vs non-native container builds, I see that the memory usage actually got slightly bigger. Am I misconfiguring something? The code itself is fairly simple, consisting of a Hibernate class that interacts with a single Postgres table. Thank you.

Expected behavior

Smaller file memory usage when deployed into Docker

Actual behavior

Larger memory size in Docker

How to Reproduce?

Native container build: mvnw clean install -Dnative "-Dquarkus.container-image.build=true" "-Dquarkus.native.container-build=true" "-Dquarkus.buildpack.builder-env.BP_JVM_VERSION=17" leads to a Docker file of size 300.95 MB, and docker stat of:

CONTAINER ID   NAME             CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O   PIDS
f9f9dac37ad3   focused_swartz   0.10%     230.2MiB / 7.671GiB   2.93%     10.6kB / 8.04kB   0B / 0B     50

vs

Non-native container build: mvnw clean install "-Dquarkus.container-image.build=true" "-Dquarkus.buildpack.builder-env.BP_JVM_VERSION=17" leads to a Docker file of size 254.35 MB - it builds properly but I'm currently unable to reproduce this (ERROR: failed to launch: determine start command: when there is no default process a command is required - will update issue when I figure this out, but from a previous run, my 'docker stat' was:

CONTAINER ID   NAME                CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O   PIDS
cdb6992ba593   reverent_bhaskara   0.09%     212.7MiB / 7.671GiB   2.71%     10.3kB / 8.08kB   0B / 0B     48      

Output of uname -a or ver

Windows 11

Output of java -version

liberica 21.0.3-12

Mandrel or GraalVM version (if different from Java)

Oracle GraalVM 21.0.3+7.1 (build 21.0.3+7-LTS-jvmci-23.1-b37)

Quarkus version or git rev

3.12.0

Build tool (ie. output of mvnw --version or gradlew --version)

3.9.7 (via Scoop)

Additional information

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.testing</groupId>
    <artifactId>rest-api-java</artifactId>
    <version>1.0.3-native</version>

    <properties>
        <java.version>21</java.version>
        <maven.compiler.release>21</maven.compiler.release>
        <compiler-plugin.version>3.13.0</compiler-plugin.version>
        <jpastreamer.version>3.0.3.Final</jpastreamer.version>
        <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
        <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
        <quarkus.platform.version>3.12.0</quarkus.platform.version>
        <surefire-plugin.version>3.2.5</surefire-plugin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>${quarkus.platform.artifact-id}</artifactId>
                <version>${quarkus.platform.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-arc</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-hibernate-orm-panache</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-jdbc-postgresql</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkiverse.jpastreamer</groupId>
            <artifactId>quarkus-jpastreamer</artifactId>
            <version>${jpastreamer.version}</version>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-container-image-buildpack</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit5</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-rest-jackson</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-smallrye-openapi</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${compiler-plugin.version}</version>
                <configuration>
                    <compilerArgs>
                        <arg>-parameters</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <systemPropertyVariables>
                        <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                        <maven.home>${maven.home}</maven.home>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <configuration>
                    <systemPropertyVariables>
                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                        <maven.home>${maven.home}</maven.home>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
            <plugin>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>quarkus-maven-plugin</artifactId>
                <version>${quarkus.platform.version}</version>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <goals>
                            <goal>build</goal>
                            <goal>generate-code</goal>
                            <goal>generate-code-tests</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>native</id>
            <activation>
                <property>
                    <name>native</name>
                </property>
            </activation>
            <properties>
                <skipITs>false</skipITs>
                <quarkus.package.jar.type>uber-jar</quarkus.package.jar.type>
                <quarkus.native.enabled>true</quarkus.native.enabled>
            </properties>
        </profile>
    </profiles>
</project>
quarkus-bot[bot] commented 3 weeks ago

/cc @Karm (mandrel), @galderz (mandrel), @zakkak (mandrel,native-image)

geoand commented 3 weeks ago

Hey,

Thanks for trying out Quarkus!

You should not use docker stats to measure memory usage