#6 Foreign-Memory Access API
Don't Put Fat Jars in Docker Images. Micronaut vs Quarkus vs Spring Boot. UUIDs and Memeid. Continuous Monitoring With JDK Flight Recorder.
Welcome to the sixth Dukesletter edition!
The fifth edition was delivered to 425 persons and reached 620 views.
JDK 14 release came full of features and we still have more features to introduce!
1.- Foreign-Memory Access API
Probably you will never use this feature in your code and you will never hear about it again, but libraries and frameworks that you use will use it.
Some frameworks and tools need to manage large byte arrays of data (usually off-heap), and need to access different segments of it in an efficient and safe way.
These tools use sun.misc.Unsafe
to work with this memory, but the class has been deprecated and the JDK must offer an alternative.
This alternative for foreign-memory access has been developed in the JEP 370, still in incubator mode.
You can find a good introduction in “JDK 14 Foreign-Memory Access API Overview”. In the article, you will find a talk by Maurizio Cimadamore explaining how it works.
But I prefer another version of the same presentation by Brian Goetz in the latest Devoxx:
My favorite part is when Brian explains how the performance evolves using different techniques, or how new Graal compiler can improve the performance using better scape analysis.
The presentation is an example of how byte code can be optimized by the C2 compiler allowing to create simple and performant code without using hacks.
2.- Don't Put Fat Jars in Docker Images
Docker has achieved to become a de facto standard, and if you want to be cool you must deploy your application to Kubernetes.
How do you package your applications? Which base image do you use? We still don't have a standard way of dockerize a Java application.
One of the proposals is to avoid the usage of Fat Jars, using some properties of docker images. In “Don't Put Fat Jars in Docker Images“, Philipp Hauer explains that using image layering and registry caching you can create incremental builds and very small artifacts.
The article is a good opportunity to learn how a docker image is created and how to inspect its content.
In the Java world, the proposed tool to build these layered images is Jib. To see a complete process: from Spring Boot application creation to deployment to Docker Hub, I recommend this article: “Create Fast and Easy Docker Images With Jib”
3.- Micronaut vs Quarkus vs Spring Boot
Until recently we had few options to create an “Enterprise Application”, but thanks to OCI and Red Hat, we have two more players on the ground: Micronaut and Quarkus.
But, how fast is the same application using different frameworks? How much memory do they consume? In the era of ephemeral Microservices, how long does it take them to start?
As an experiment, Graeme Rocher (creator of Grails and Micronaut), tries to compare these modern frameworks in “Micronaut vs Quarkus vs Spring Boot performance on JDK 14”.
The experiment is simple and only measure frameworks overhead. Remember that your code is the code that has bottlenecks, creates a lot of objects that consume a lot of memory or pauses threads in I/O. Frameworks help you with the infrastructure but will not solve this kind of problems.
4.- UUIDs and Memeid
In a distributed computing world sometimes we can not use a centralized sequence generator, and we must use a different paradigm. One of the proposed techniques is to use UUIDs.
Java standard library provides an implementation of UUIDs specification, but doesn’t provide all versions and have weird behavior in comparison function.
People from 47 Degrees have implemented an alternative version with better support of the specification and different implementation of comparison function.
They present it in “Introducing memeid: An RFC-compliant library for working with UUIDs”.
You don’t need to create a complex library full of functionalities to release Open Source code. Small projects with simple purposes can also be a good way to introduce you to this world.
If you are interested in distributed system and want to learn more about distributed IDs I propose these articles:
The origin and history of the UUID, very interesting: “A brief history of the UUID”
Different strategies to generate distributed IDs: “Generating unique IDs in a distributed environment at high scale”
5.- Continuous Monitoring With JDK Flight Recorder
In the latest Dukestter edition I introduced Java Flight Recorder and how it will improve our monitoring capabilities.
At the same time, DevDotNext Digital Edition was celebrated, and one of the talks was about this topic. I invite you to continue learning about it with this talk: