Skip to content

Spring Native experience applied in Microservices that use GraalVM native-image as a bytecode compiler.

Notifications You must be signed in to change notification settings

thiaguimcavalcanti/spring-native-lab

Repository files navigation

Getting Started

Motivation

Stack

  • Gradle 7.0.2
  • jdk 21.1.0.r11-grl (OpenJDK Runtime Environment GraalVM CE 21.1.0 (build 11.0.11+8-jvmci-21.1-b05))
  • spring-boot-starter-webflux
  • spring-native

Project organization

Two sub-projects were created to separate the logic:

  1. spring-native-microservice sub-project:
    Microservice project contains the Spring-Native setup to run this application on a GraalVM Native Image through Docker container
  2. standard-microservice sub-project:
    Simple microservice project using spring-boot-starter-webflux

Both projects contain only one controller class with the same content just to test purpose:

@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("/getName")
    public Mono<String> getName() {
        return Mono.just("Ragnar Lothbrok (Vikings)");
    }
}

How-to Run

There is a README.md file inside each sub-projects describing how to run them.

Test

It was pretty straightforward. To perform the startup time test, I ran both subprojects as described in the README.md file, and the results were amazing. Take a look below :)

Results

standard-microservice

  • Build time: ~7 seconds
  • Start time: ~3 seconds (too much time)

spring-native-microservice

  • The $ gradle bootBuildImage command takes ~10 minutes to build a new Docker image

  • And the startup time was unbelievable 0.171 seconds \o/

Final comment

  • The startup time of the microservice project using Spring Native running on Native Image was ~17x faster than a standard microservice project running on HotSpot JVM.

My thoughts

The Spring team is doing a great job related to Spring Native.

This plugin came to compete with Micronaut and Quarkus, but I believe that the Spring team has a lot of work to do to release a version more trustful. I say that because in this simple POC, I faced many warnings and errors during the docker image build (maybe I forgot to set up something).

Anyways, congratulations Spring team!!!!! I'm impressed with the results and looking forward to testing new releases. \o/

Releases

No releases published

Packages

No packages published

Languages