Code Monkey home page Code Monkey logo

spring-cds-demo's Introduction

Spring CDS demo

This repository is intended to demonstrate how to use Spring Framework 6.1 CDS support.

See also:

Pre-requisites

While it is possible to use Java 17, it is recommended to use Java 21 which provide a more advanced CDS support. You should also use a Java distribution with a prebuilt CDS archive.

You can use SDK manager to install and use such Java distribution:

sdk env install
sdk env

Check the application starts correctly without CDS involved:

./gradlew bootRun

Check the startup time, for example on my MacBook Pro M2:

Started CdsDemoApplication in 0.575 seconds (process running for 0.696)

Build and run with CDS

You can either just run the cds.sh script and perform those steps manually.

Build the project.

./gradlew build

Unpack the Spring Boot application to a JAR structure suitable for optimal performances with CDS:

./unpack-executable-jar.sh -d build/unpacked build/libs/cds-demo-0.0.1-SNAPSHOT.jar

This should create the following JAR structure:

build
└── unpacked
        ├── application
        │   └── spring-cds-demo-1.0.0-SNAPSHOT.jar
        ├── dependencies
        │   ├── ...
        │   ├── spring-context-6.1.0.jar
        │   ├── spring-context-support-6.1.0.jar
        │   ├── ...
        └── run-app.jar"

Perform the CDS training run (here with Spring AOT optimizations) in order to create an additional build/unpacked/application.jsa file:

java -Dspring.aot.enabled=true \
-Dspring.context.exit=onRefresh \
-XX:ArchiveClassesAtExit=build/unpacked/application.jsa \
-jar build/unpacked/run-app.jar

And finally run the application with CDS optimizations (here with Spring AOT optimizations):

java -Dspring.aot.enabled=true \
-XX:SharedArchiveFile=build/unpacked/application.jsa \
-jar build/unpacked/run-app.jar

Check the startup time, for example on my MacBook Pro M2:

Started CdsDemoApplication in 0.289 seconds (process running for 0.384)

Build and run optimized container images CDS

Check content of the Dockerfile and run the create-container-image.sh script, or run manually:

docker build -t sdeleuze/spring-cds-demo .

Then run the run-container.sh script, or run manually:

docker run --rm -it -p 8080:8080 sdeleuze/spring-cds-demo

You can also try to deploy the resulting container image to your Cloud or Kubernetes platform. Make sure that the server where you deploy the application has the same CPU architecture than the one where you built the CDS archive.

spring-cds-demo's People

Contributors

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