---
title: "How I Achieved Incredibly fast Java Micronaut Service Startup Times with GraalVM"
date: 2020-05-20T00:00:00+00:00
author: "poornerd"
tags: ["java", "graalvm", "micronaut"]
canonical: https://www.poornerd.com/2020/05/20/incredibly-fast-java-service-startup-speed-graalvm.html
source: Raw Markdown twin of the HTML article; content is the original source.
---
Despite my [Micronaut](https://micronaut.io) Java service having a fast startup time, I wanted to see if I could get it starting even fast for production.  The short answer was YES.

In order to do this, I used GraalVM - an advanced optimizing compiler with the ability to generate executables - even for a Java application.

First I used [https://sdkman.io](https://sdkman.io) to install any [GraalVM](https://www.graalvm.org).
```
sdk use java 20.0.0.r11-grl
```
Then I started my micronaut service:

```
CFE-NB-1023:vin-check bporter$ ./gradlew run

> Task :run
OpenJDK 64-Bit Server VM warning: forcing TieredStopAtLevel to full optimization because JVMCI is enabled
13:26:30.738 [main] INFO  io.micronaut.runtime.Micronaut - 
Startup completed in 760ms. Server Running: http://localhost:5000

```
It started in 760ms - which still is not bad for a Java service starting using a JIT.

![Micronaut Speed startup times with GraalVM](/images/posts/graal-startup.png){:class="img-fluid w-100"}

Then I compiled the executable with GraalVM and got it down to __32ms!!__

```
CFE-NB-1023:vin-check bporter$ ./micronaut-graal-app 
13:26:40.739 [main] INFO  io.micronaut.runtime.Micronaut - 
Startup completed in 32ms. Server Running: http://localhost:5000
```

In order to achieve that, I followed the instructions on this page [https://guides.micronaut.io/micronaut-creating-first-graal-app/guide/index.html](https://guides.micronaut.io/micronaut-creating-first-graal-app/guide/index.html) which basically involved:

1. ````gu install native-image````
1. Adding some options to my build.gradle:
```
compileOnly "org.graalvm.nativeimage:svm"
annotationProcessor "io.micronaut:micronaut-graal" 
```
1. Adding a ````native-image.properties```` to my ````resources/META-INF/native-image/example.micronaut/complete-application```` directory
1. Assemble the distribution, and create the GraalVM executable:
```
 ./gradlew assemble
native-image --verbose --no-server -cp build/libs/vin-check-0.1-all.jar
```
1. Run the image with ````./micronaut-graal-app````

