Repository navigation
feat: native build and startup measurements - #8
Merged
Merged
Conversation
The ignore file excludes everything except what the image builds need. The native image is built by a Mandrel builder image that ships no Maven, so it runs the project's Maven wrapper, and the wrapper script and its .mvn directory must therefore be part of the context. Everything else stays excluded, so the context remains small and free of local files such as keys and build output.
The first stage compiles the application to a native executable with Mandrel, Red Hat's GraalVM distribution, through the pom's native profile. The second stage copies only that binary onto a micro runtime image with the few C libraries it links against: no JVM, no Maven and no sources ship, which is where the small image and the fast start come from. It mirrors Dockerfile.jvm on purpose, with the dependency download cached before the sources are copied, tests skipped in the build stage because Dev Services needs a Docker daemon, and a non-root user at runtime.
The script starts the application in the mode it is given, waits for the readiness endpoint, sends the same fixed mix of requests, and prints one table row with the time until ready, the startup time Quarkus reports and the resident memory after the load. Running the identical script on the JVM jar and on the native binary is what makes the comparison fair. The memory is read after the load and not at idle, since a JVM grows once it has served traffic while a native binary starts close to its steady size.
A separate job builds the native executable in a Mandrel container, measures JVM mode against native mode with the measurement script, publishes the table in the job summary, and checks that Dockerfile.native builds. It is independent of the test job, so its many minutes never delay the fast feedback of the tests. Unlike the test job it declares a PostgreSQL service: Dev Services only exists in dev and test mode, and the packaged application needs a real database to start.
The native build failed because a static SecureRandom is created while the GraalVM image is built: its seed would be frozen into the image heap, and every started instance would produce predictable tokens, so the compiler refuses it. The generator is now a field of the application scoped bean, created when the running application starts. It is seeded for real at run time, and behaves the same in JVM and native mode, so this is a correctness gain and not only a workaround.
The port was given as a -D option after the command, which for a jar lands after -jar and is passed to the application as an ordinary argument, so the JVM ignored it and the script probed a port nobody listened on, forever. An environment variable is read by Quarkus in every packaging mode, so the same line now works for the jar and for the native binary. The readiness wait also gives up after two minutes and prints the end of the log, so a misconfigured start fails the job with an explanation instead of hanging it.
The notes explain the two ways to build the executable, the Dockerfile and the Maven container build, and give the figures measured by the CI job for the same load in both modes: startup goes from about four seconds to about a tenth of a second, and memory after the load is about halved. They also list the caveats, so the numbers are read as an order of magnitude and not as a benchmark. They record the one code change the native compiler forced, the static random generator, because it shows the closed world model in practice: whatever runs at class initialisation is executed at build time. They also say why the build was done in CI, since a local Docker VM of 1.4 GiB cannot hold the compiler.
The four tasks are ticked. The local build task carries a note saying the executable was built by the CI job, because the development machine's Docker VM is too small for the native compiler, and points to the notes file for the figures.
The exit trap now waits for the process after stopping it, so when the JVM measurement is followed by the native one, the port is really free and the second start cannot be answered by the first application still shutting down. The load loop also checks each status code. A refused connection or a server error now fails the run instead of being counted as load, since figures taken while the requests never reached the application would look plausible and mean nothing.
EdgarEldy
marked this pull request as ready for review
September 19, 2026 08:13
20 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Branch
feature/native-build (bonus)
Task checklist
Dockerfile.native(multi-stage: Mandrel builder image, micro runtime image)mvn package -Dnative -Dquarkus.native.container-build=true, by the CI job (the local Docker VM is 1.4 GiB, too small for native-image: exit 137)docs/native-build.md).github/workflows/ci.ymlextended with anative-buildjobCommit summary
Dockerfile.nativeand the.dockerignorechange it needs (Maven wrapper in the context)scripts/measure-startup.sh, the measurement used by CI for both modesDockerfile.nativeAuthServiceImplno longer holds a staticSecureRandom(refused by the native build; also a real seeding fix)docs/native-build.md, README tickedTest checklist
mvn verifyis green on the whole project (181 tests)Code review checklist
ApiResponse<T>, errors are RFC 9457 Problem Details, neverApiResponseon an error path@PermissionsAllowed), no manual permissionif@CacheResulthas its matching@CacheInvalidate(unchanged)AuditLogger(n/a)Known limits: the native job compiles twice (about ten minutes each); the figures come from one run on a shared runner.