This article will know Quarkus, a technology that allows you to efficiently run Java applications in Kubernetes containers. To understand what Quarkus is and the advantages of using it, we will analyze the evolution of the architecture of Java applications that has led us to this framework that adapts Java to cloud computing. Let’s go there!

  • Java and JVM
  • Java and Cloud
  • Native compilation
  • Java and Docker
  • What is Quarkus?
  • Characteristics of Quarkus
  • How does Quarkus work?

Java and JVM

The traditional architecture of Java applications is based on an intermediate layer, the so-called virtual machine (JVM), which acts as a mediator between the application and the operating system. The JVM interprets the precompiled Java bytecode in particular hardware and working system environment, ensuring the portability of the original Java source code.

To do this, it deals with functions such as the reservation of memory space, the release of unused memory (garbage collection), the assignment of variables to registers and stacks, calls to the host system, and the scheduling of threads … This traditional architecture can be represented in this way:

Traditional Java architecture. Source: Own elaboration.

Java and Docker

The goal of the JVM, we say, is to make the source code independent of the specific machine that executes it. However, another container-oriented architecture has become famous thanks to technologies such as Docker.

In this case, between the operating system and the applications, a virtual layer is also established that achieves independence from the machine – such as a JVM, but now not only from Java but from any technology – in which to have a series of isolated and independent containers from each other.

Thus, we can have a container that runs a jar in Java 6, another with a microservice in Java 11, and another with an application server. Each container will work with its JVM on the same Docker layer. The scheme would be in this case:

Container-based Java architecture. Source: Own elaboration.

Java and Cloud

From here, it has evolved into architecture with an orchestrator. We no longer talk about applications deployed on containerized servers but about a cluster of nodes managed by an orchestrator such as Kubernetes.

This allows you to outsource the management of the administration (dynamic scaling of the needs of each application, load balancing, fault tolerance) and focus on the business logic as such that our set of applications must implement. This scheme has favoured the serverless model, in which we access different micro services and functions (FaaS) distributed to realize our business logic.

Java architecture with the orchestrator. Source: Own elaboration.

The underlying idea of the serverless model is low power: applications are stopped and boot only when required; after doing their job, they free up resources and shut down. This leads to cost reduction since you only pay for effective processing instead of having an application built consuming resources continuously.

But in this model, the start time must be milliseconds so that the speed of response is not affected. The boot time of Java applications, of several seconds, made this model unfeasible.

Native compilation

If we look at the second diagram, it seems clear that JVMs become redundant with a virtualization layer like Docker. If the idea of the JVM was that the operating system would be transparent to the Java application, the point is that Docker is already fulfilling this function. In such cases, it is possible to assess the convenience of deleting the JVM and compiling each Java application natively. The OS is responsible for the tasks carried out by the JVM.

The first advantage of this native build is a drastic reduction in application startup time. This allows for something hitherto unthinkable: a server less approach to our Java applications.

What is Quarkus?

Quarkus is a technology that enables Java as an effective platform for the current serverless architecture model, microservices, functions as a service (Faas) and orchestrated containers. That is, for the cloud computing approach.

Specifically, the primary objective of Quarkus is the efficient execution of Java applications in Kubernetes containers (it allows to automatically generate Kubernetes resources by default and deploy container images in a single step), both for JVMs native compilation.

It is also designed to work with popular Java standards, frameworks and libraries, such as Spring (not so much Spring Boot, which is its direct competitor), Apache Kafka, RESTEasy (JAX-RS), Hibernate ORM (JPA), Camel, etc.

Characteristics of Quarkus

The main features of Quarkus are:

  • There are short application boot times (300 times faster than traditional Java applications).
  • Low memory consumption (1/10 of traditional Java applications).
  • Allows you to combine imperative and reactive code (non-blocking, subscription-based).

For example, suppose a traditional Java microservice takes several seconds to boot and uses several hundred megabytes of memory in Quarkus. In that case, a similar natively compiled microservice takes up tens of milliseconds and consumes only a few tens of megabytes of memory.

How does Quarkus work?

For the native compilation, Quarkus uses GraalVM, a performance-optimized virtual machine that can execute code from different programming languages, not only the usual JVM (Kotlin, Scala. Clojure) but others such as C++, Python or JavaScript.

In any case, it is not compulsory to compile natively for an efficiency gain. Quarkus uses ahead-of-time (AOT) to optimize the jar to boot up quickly and with less RAM consumption than a traditional microservice on top of JVM.

The following diagram compares the boot time and memory consumption of a traditional microservice, another in Quarkus. And another in Quarkus with native compilation:

Comparison of the boot time and memory consumption of a conventional microservice. Another in Quarkus and another in Quarkus with the native reader.

Conclusion

Quarks is an exciting framework for implementing Java on Kubernetes. It is other step in the development of Java application architecture, which we have reviewed in this article.

Specifically, in this post, we have seen that:

  • The JVM virtual machine, which allows the portability of the same source code to different platforms. Is inadequate for the current cloud computing paradigm.
  • Virtualization using isolated Docker containers makes it possible to do without the JVM for Java code using native compilation.
  • Quarkus, through the use of Docker and Kubernetes, manages to make Java a technology suitable for cloud computing.
  • GraalVM offers native build tools for Quarkus.

In the upcoming essay. We will see how to create a simple microservice with Quarkus and compile it natively using GraalVM.

Review Quarkus: What Features has and Why Use it?.

Your email address will not be published.