Recently I followed some Mongo DB courses and attended the Spring I/O 2023.
So I decided to practice a bit. This project is the result.
Currently is just a simple POC integration of Mongo DB and Quarkus
There is a live version at the link https://springio23.fugerit.org/photobook-demo/home/index.html
This is an alternate version of the springboot project based on quarkus
| software | docker compose | local build and run |
|---|---|---|
| no | yes | |
| no | yes | |
| no | yes | |
| no | yes | |
| yes | no |
docker-compose -f src/main/docker/docker-compose.yml up -d- Create mongo db instance with db initialization (script src/test/resources/mongo-db/mongo-init.js) :
docker run --rm -p 27017:27017 --name MONGO8 -v `pwd`/src/test/resources/mongo-db/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js mongo:8.2.3This will start a mongo db linked on the default port and with the default username/password (root/example).
- Start the application in dev mode
The back end
mvn quarkus:devAnd front end
cd src/main/react
npm install
npm run start- Access home page
http://localhost:8080/photobook-demo/home/index.html
In case you want a custom mongo db connection :
| key | dedault |
|---|---|
| MONGODB_URL | mongodb://localhost:27017/photobook_demo |
Other custom environment variables :
| key | dedault | description |
|---|---|---|
| JAVA_OPTS_APPEND | append java options (for instance '-Xmx1g') |
For the Dockefile.jvm build, see the RedHat UBI OpenJDK image documentation for more options.
It is possible to compile the application to a single jar package :
mvn package -PbuildreactAnd then run
java -jar target/quarkus-app/quarkus-run.jarThe code has been set for native compilation with GraalVM (tested with GraalVM 22.3 CE).
It is possible to compile :
mvn install -Dnative -PbuildreactAnd then run
./target/quarkus-photobook*-runnerRefer to Quarkus Documentation for more informations.
Build quarkus application (jar)
mvn package -P buildreactBuild container openjdk
docker build -t quarkus-photobook-jvm -f src/main/docker/Dockerfile.jvm .Running the container :
docker run -it -p 8080:8080 --name quarkus-photobook-jvm quarkus-photobook-jvmBuilding the native image :
mvn install -Dnative -PbuildreactBuilding the container image :
docker build -t quarkus-photobook-native -f src/main/docker/Dockerfile.native .Running the container :
This section is based on https://github.com/alina-yur/native-spring-boot.
One of the most powerful performance optimizations in Native Image is profile-guided optimizations (PGO).
- Build an instrumented image:
mvn package -Dnative -Pinstrumented- Run the app and apply relevant workload:
mv ./target/quarkus-photobook*runner ./target/quarkus-photobook-instrumented./target/quarkus-photobook-instrumentedhey -n=30000 http://localhost:8080/photobook-demo/api/photobook/view/listhey -n=30000 http://localhost:8080/photobook-demo/api/photobook/view/images/springio23/language/it/current_page/1/page_size/5after you shut down the app, you'll see an iprof file in your working directory.
- Build an app with profiles (they are being picked up via
<buildArg>--pgo=${project.basedir}/default.iprof</buildArg>):
mvn package -Dnative -PoptimizedPrerequisites :
- running mongo db
heyinstalledpsrecordinstalled
At the end of a run, an image will be plotted in the target folder.
mvn clean package./src/main/script/bench-jit.shFollow steps in 'Native optimization : PGO' section
./src/main/script/bench-native.shSample result of JIT benchmark run :
Sample result of native (AOT) benchmark run :
| Layer | 2024 version |
|---|---|
| Persistence | MongoDB 8 |
| Java version | GraalVM 21 |
| API REST | Quarkus 3.11.x |
| Node JS | Node 20 |
| Front end package | Vite |
| Front end UI | React 18.3 |
Prerequisites :
- google cloud account
- GCloud CLI
Simple app.yaml for AOT and Simple app.yaml for JIT
Customize the app.yaml and run gcloud
For JIT version the uber kar packaging is needed :
mvn package -Dquarkus.package.jar.type=uber-jargcloud quarkus-photobook-runner.jar --appyaml=src/main/appengine/app-jit.yamlFor JIT version or
gcloud quarkus-photobook-runner --appyaml=src/main/appengine/app-aot.yamlFor AOT version
Further reference :
- https://cloud.google.com/sdk/gcloud/reference/app/deploy
- https://quarkus.io/guides/deploying-to-google-cloud
Prerequisites :
- container environment (docker / podman)
- Kubernates (for instance minikube)
- Knative
After setting up Knative, Customize the quarkus-photobook-jit.yaml or quarkus-photobook-aot.yaml service deployment.
And run
kubectl apply -f quarkus-photobook-jit.yamlFor JIT version or
kubectl apply -f quarkus-photobook-aot.yamlFor AOT version

