Skip to content

feat: native build and startup measurements - #8

Merged
EdgarEldy merged 9 commits into
developfrom
feature/native-build
Sep 19, 2026
Merged

EdgarEldy merged 9 commits into
developfrom
feature/native-build

Conversation

@EdgarEldy

@EdgarEldy EdgarEldy commented Sep 19, 2026 •

Copy link
Copy Markdown
Owner

Branch

feature/native-build (bonus)

Task checklist

  • Dockerfile.native (multi-stage: Mandrel builder image, micro runtime image)
  • Native executable built with 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)
  • Startup and memory measured, JVM vs native, same load: 4021 ms / 249 MB vs 156 ms / 127 MB (docs/native-build.md)
  • .github/workflows/ci.yml extended with a native-build job

Commit summary

  • Dockerfile.native and the .dockerignore change it needs (Maven wrapper in the context)
  • scripts/measure-startup.sh, the measurement used by CI for both modes
  • CI job that builds native, measures, and checks Dockerfile.native
  • fix: AuthServiceImpl no longer holds a static SecureRandom (refused by the native build; also a real seeding fix)
  • notes in docs/native-build.md, README ticked

Test checklist

  • Unit tests pass
  • Integration tests pass (where the branch's checklist calls for them)
  • mvn verify is green on the whole project (181 tests)

Code review checklist

  • No business logic in JAX-RS resources
  • Success responses are wrapped in ApiResponse<T>, errors are RFC 9457 Problem Details, never ApiResponse on an error path
  • Permission checks are declarative (@PermissionsAllowed), no manual permission if
  • Every @CacheResult has its matching @CacheInvalidate (unchanged)
  • Every RBAC mutation calls AuditLogger (n/a)
  • The database schema only changes through a Flyway migration (no change)
  • No manual Testcontainers setup (Dev Services only; the CI native job runs the packaged app, so it declares a PostgreSQL service on purpose)
  • Commits are atomic, follow Conventional Commits, no em dash, no Claude/Anthropic mention

Known limits: the native job compiles twice (about ten minutes each); the figures come from one run on a shared runner.

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 EdgarEldy changed the title wip: native build feat: native build and startup measurements Sep 19, 2026
@EdgarEldy
EdgarEldy marked this pull request as ready for review September 19, 2026 08:13
@EdgarEldy
EdgarEldy merged commit 4836b6e into develop Sep 19, 2026
3 checks passed
@EdgarEldy EdgarEldy mentioned this pull request Sep 19, 2026
20 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant