Coder Social home page Coder Social logo

springboot-photobook's Introduction

Springboot Photobook Demo App

Keep a Changelog v1.1.0 badge license code of conduct Quality Gate Status Coverage Docker images

Introduction

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 Spring Boot.

There is a live version at the link https://springio23.fugerit.org/photobook-demo/home/index.html

Prerequisites

software docker compose local build and run
Java runtime version no yes
Java build version no yes
Apache Maven no yes
Node JS no yes
Docker yes no

Quickstart

Start via docker compose

docker-compose -f src/main/docker/docker-compose.yml up -d

access home page

http://localhost:8080/photobook-demo/home/index.html

Start in dev mode

  1. 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.0.0-rc7

This will start a mongo db linked on the default port and with the default username/password (root/example).

  1. Start the application in dev mode

The back end

mvn spring-boot:run

And front end

cd src/main/react
npm install
npm run start
  1. Access home page

http://localhost:8080/photobook-demo/home/index.html

project environment variables

In case you want a custom mongo db connection :

key dedault
MONGODB_URL mongodb://localhost:27017/photobook_demo

container environment variables

Other custom environment variables :

key dedault description
JAVA_OPTS_APPEND append java options (for instance '-Xmx1g')

Spring Boot package

It is possible to compile the application to a single jar package :

mvn package -Pbuildreact

And then run

java -jar ./target/springboot-photobook-*.jar

Native image compilation

The code has been set for native compilation with GraalVM (tested with GraalVM 22.3 CE).

It is possible to compile :

mvn -Pbuildreact,native clean native:compile

And then run

./target/springboot-photobook

Refer to Spring Boot Documentation for more informations.

Docker image

docker container (jvm)

Build spring application (jar)

mvn package -P buildreact

Build container openjdk

docker build -t springboot-photobook-jvm -f src/main/docker/Dockerfile.jvm .

Running the container :

docker run -it -p 8080:8080 --name springboot-photobook-jvm springboot-photobook-jvm

docker container (native)

Building the native image :

mvn -Pbuildreact,native clean native:compile

Building the container image :

docker build -t springboot-photobook-native -f src/main/docker/Dockerfile.native .

Running the container :

docker run -it -p 8080:8080 --name springboot-photobook-native springboot-photobook-native

Native optimization : PGO

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).

  1. Build an instrumented image:
mvn -Pnative,instrumented native:compile
  1. Run the app and apply relevant workload:
./target/springboot-photobook-instrumented
hey -n=30000 http://localhost:8080/photobook-demo/api/photobook/view/list
hey -n=30000 http://localhost:8080/photobook-demo/api/photobook/view/images/springio23/language/it/current_page/1/page_size/5

after you shut down the app, you'll see an iprof file in your working directory.

  1. Build an app with profiles (they are being picked up via <buildArg>--pgo=${project.basedir}/default.iprof</buildArg>):
mvn -Pnative,optimized native:compile

Benchmark scripts

Prerequisites :

  • running mongo db
  • hey installed
  • psrecord installed

At the end of a run, an image will be plotted in the target folder.

1. Benchmark JIT

mvn clean package
./src/main/script/bench-jit.sh

2. Benchmark native

Follow steps in 'Native optimization : PGO' section

./src/main/script/bench-native.sh

3. Benchmark result

Sample result of JIT benchmark run :

JIT Benchmark Result

Sample result of native (AOT) benchmark run :

Native Benchmark Result

application stack

Layer 2023 version 2024 version
Persistence MongoDB 6 MongoDB 8
Java version GraalVM 17 GraalVM 21
API REST SpringBoot 3.0.0 SpringBoot 3.3.0
Node JS Node 18 Node 20
Front end package React scripts Vite
Front end UI React 18.2 React 18.3

Deploy on Google App Engine

Prerequisites :

  • google cloud account
  • GCloud CLI

Simple app.yaml for AOT and Simple app.yaml for JIT

Customize the app.yaml and run gcloud

gcloud micronaut-photobook-*runner.jar --appyaml=src/main/appengine/app-jit.yaml

For JIT version or

gcloud micronaut-photobook --appyaml=src/main/appengine/app-aot.yaml

For AOT version

Further reference :

Deploy on KNative

Prerequisites :

  • container environment (docker / podman)
  • Kubernates (for instance minikube)
  • Knative

After setting up Knative, Customize the micronaut-photobook-jit.yaml or micronaut-photobook-aot.yaml service deployment.

And run

kubectl apply -f micronaut-photobook-jit.yaml

For JIT version or

kubectl apply -f micronaut-photobook-aot.yaml

For AOT version

springboot-photobook's People

Contributors

fugerit79 avatar mttfranci avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.