GraalVM is here!By Laurent Doguin,
Good news everone, we are all super happy to tell you our JVM image has been updated substantialy. We now support OpenJDK 12 and GraalVM CE!
If you follow what's going on in the JVM space you have seen there is more and more choices available when it comes to running JVM-based applications. And we now support GraalVM CE. If you have no idea what it is, the best, simple explaination can be found on Julien Ponge's medium: https://medium.com/@jponge/the-graalvm-frenzy-f54257f5932c
And as he explains that way better than I, I will jump into the how to run a GraalVM application on Clever Cloud.
We first need to find an appropriate Hello world project. Being a Ratpack fan I looked on Github and found this: https://github.com/wololock/ratpack-graalvm-demo
This is a gradle project with a script to build a native image, basically a binary with everything needed to run the application. No need for a JVM. So this is what we are going to build.
First to create the application, if you have clever-tools you can run:
clever create --type gradle --plan M graalPack
Now we need to setup the right environment variables.
clever env set CC_JAVA_VERSION graalvm-ce # Select GraalVN CE as Java Version clever env set GRADLE_DEPLOY_GOAL shadowJar # Specify the gradle goal, here we want to build a full jar. clever env set CC_PRE_RUN_HOOK ./build-native-image.sh # run the native image build clever env set CC_RUN_COMMAND ./ratpack-graalvm-demo # specify the path of the native executable
I have modified a couple of things to make sure it would work smoothly on Clever Cloud. First thing, always define a rootProject name because gradle will pick the containing folder, which in our case the random application id, and generate the jar name with it. So you can't really use it in a script. Here's one liner to do it:
echo 'rootProject.name = "ratpack-graalvm-demo"' > settings.gradle
The script already run
gradlew shadowJar. I have removed it since this step is already made by Clever Cloud. Of course you could run it locally and only push the executable. This would also work.
Don't forget to add these changes to your git repository:
git add settings.gradle build-native-image.sh && git commit -m"cleverify"
We are building a native image and this can be a super greedy process in terms of memory. To make sure we have some headroom we are going to use a bigger scaler. Run
clever scale --flavor L to get the proper size. This might depend on the build you are running. Static analysis is not cheap. Later this week we'll show you how to proceed differently with a new CI project :) But for now we'll stick to a bigger scaler.
Now all you have to do is run
clever deploy and you will have your native image running on Clever Cloud. Benefits are mostly a reduced memory footprint and better performances at cold start. You can find more informations about this on the following blog post Ratpack on GraalVM - how to start?.
In the next days you can expect support for cool GraalVM features like the support for TruffelRuby or [FastR])(https://github.com/oracle/fastr). Let us know if you have any questions in the comments below!
By clicking "Get started" I agree to Clever Cloud's Terms and Conditions
Head of Developer Relation @clever_cloud. Devoxx Champion. I am also a nerdy metal head living in Paris.