Building serverless Scala services with GraalVM native image

Click for: original source

Using GraalVM’s Native Image tool to create native executables. Author describes the steps necessary to build a native executable from a simple http4s web service. There is also complete code accompanying this example. By Noel Welsh.

Before going into the details it’s worth going over a bit of background. GraalVM is a new Java virtual machine and associated tools that brings increased performance compared to the older Hotspot VM. Native Image is one of the most interesting tools that comes with GraalVM.

The main steps mentioned in the article are:

  • Install GraalVM locally (this is optional, but it is faster to test this way)
  • Writing code (the fun part!)
  • One-off configuration so that GraalVM can handle uses of reflection and Unsafe
  • Creating a Docker image to build the executable (optional if you are developing on the same platform you’re deploying to) and
  • Creating a Docker image to deploy the executable (again, optional)

Creating an executable from Scala code using GraalVM Native Image is quite straightforward. One of the attractions of native executables is faster startup and reduced memory consumption compared to the standard JVM. Great!

[Read More]

Tags java scala jvm performance