Quarkus
In this new edition of Inspiring Technology, our technology trend Hunters talk about Quarkus, a framework developed to run Java programmes in containers. Read on!
Quarkus is a Java framework created by Red Hat with a focus on cloud-based environments, specifically Kubernetes and serverless platforms. The framework strives to offer the best possible development experience by adopting standards, integrations and simple configurations.
Kubernetes-native
Quarkus includes fundamental features for Kubernetes development and deployment, such as metrics, tracing, health reporting, debugging on a remote cluster and configurations based directly on Kubernetes ConfigMaps.
By using an extension, Quarkus can generate all the artefacts and configurations needed for deploying and upgrading versions of a service in a Kubernetes cluster.
Fewer resources and faster start-up
Start-up time and resource usage are two vital aspects to cloud-based environments. Minimising these allows for rapid scaling, cost reduction in systems with usage-based billing, fast response times in functions-as-a-service and greater efficiency in systems with a large number of concurrently running services.
To achieve this, Quarkus runs as many processes as possible at compile time: configuration analysis, classpath resolution, class loading, etc. This preprocessing generates more optimised executables, with faster start-up times and less resource usage compared to other frameworks that perform these actions at runtime, such as Spring.
Native compilation with GraalVM
Native builds can further reduce start-up time and resource usage by creating an artefact that the operating system can execute, with no need for a Java virtual machine.
Quarkus allows us to perform native compilations easily, without the need to install libraries or make additional configurations. To make a native build, you only have to run the goal “quarkus:build” with the “native” profile enabled.
You can also run the compilation itself in a Docker container, with the option “-Dquarkus.native.container-build=true”, allowing you to compile without having to configure the environment.
Example of command used for native compilation
Extensions
Quarkus has a wide ecosystem of extensions with a standardised configuration, so you can integrate various services and libraries: clients for identity providers like Keycloak, development of functions-as-a-service in the AWS Cloud with Lambda, configuration management in Azure, etc.
These extensions enable the integration, configuration and maintenance of supported services and libraries.
Standards-based
Quarkus leverages existing tools and knowledge by adopting existing industry standards.
This is crucial because it minimises the learning curve and adoption time for developers who have previous experience with these standards.
Quarkus uses the following standards:
- Java EE (Jakarta): REST service definition, persistence, dependency injection, validations, JSON mapping and batch jobs.
- Microprofile: environment configurations, authentication, endpoint documentation, telemetry, fault tolerance and inter-service communications.
- OpenTelemetry: traceability and collection of metrics.
Comparison of resource usage during start-up
Dev services
Quarkus automatically configures and provisions local development services in the form of fully pre-configured containers.
Among others, Dev Services supports automated development configurations for the following services: AMQP, Apicurio Registry, multiple relational databases, Elasticsearch, Kafka, Keycloak, RabbitMQ, Redis, Vault and Kubernetes clients.
For example, when you start a project in development mode and the PostgreSQL extension is installed, Quarkus will automatically create a Docker container with a PostgreSQL server and create the configuration in the project to use this container.
Compatibility with Spring
While Quarkus recommends using its own APIs, it offers a compatibility layer for the use of Spring-defined annotations by mapping to the libraries implemented and optimised by Quarkus.
Compatibility layers exist for the following Spring APIs: Spring Web, Data, Data Rest, Security, Cache and Dependency Injection.
This compatibility layer could help with the migration of projects previously implemented with Spring Boot. Moreover, it could temporarily help a team with previous Spring experience to adopt the framework.
Comparision with Spring Boot
To compare the two, the same API has been implemented in Spring Boot and Quarkus. Load tests were performed by running 80 threads, which executed a loop with 80 repetitions of 4 requests.
Both projects were run with standard and native compilation.
Start-up
The following metrecs were obtained on Docker containers during service start-up.
Comparision of resource usage during start-up
As we can see, Quarkus uses significantly less CPU and memory with standard compilation.
Meanwhile, Quarkus uses considerably less memory – 25 Mb versus 130 Mb – with native compilation. In terms of CPU usage, Spring has higher CPU usage for a while, but this quickly evens out to zero in both services.
Comparision of resource usage during start-up, native compilation
Load test
The following results were obtained from the load tests:
Comparision of resource usage during load test
In the standard versions, we can see that CPU usage remains at similar values, while memory usage is considerably lower for Quarkus.
As for the natively compiled versions, CPU usage remains similar, with Spring outperforming Quarkus in some peaks, but with higher memory usage.
Comparison of resource usage during load test, native compilation
Additional metrics
We also looked at the start-up, compilation and creation times of the Docker image.
Based on this data, Quarkus performed best with native compilation. However, native compilation can pose problems with external libraries, so it is very important to test that it works properly.
Conclusiones
Quarkus is an option to consider when deploying microservices or functions, especially those containerised in Kubernetes clusters and cloud environments.
Quarkus offers a selection of tools intended to improve development experience and time, with pre-configured settings, structures and integrations.
Moreover, because it is standards-based, the learning curve can be significantly lower if the team already has experience in developing Java EE-based applications.
We should note that, although Quarkus offers extensive documentation, other frameworks such as Spring currently have a larger community of developers.
¿Do you know about our Hunters programme?
Ser un hunter, es aceptar el reto de probar nuevas soluciones que aporten resultados diferenciales. Un grupo transversal con capacidad de generar y transferir conocimiento con la habilidad de ver anticipadamente las soluciones digitales que nos harán crecer.
Consulta más información sobre los Hunters en la web.