5

Low memory and high performance native containers are the future. Java with traditional frameworks has been difficult to work with to achieve lower level footprint with high performance like golang/rust.

But recent innovation in java that is combination of graalvm and reactive paradigm is showing very impressive results.

So, the query is regarding understanding how reactive engines are different for Spring boot vs Quarkus. Is there any reason that we should adopt quarkus native/jvm or wait for spring native to become stable and expect same performance benefits? Can somebody talk based on experiments and facts?

Jay Ghiya
  • 424
  • 5
  • 16

1 Answers1

13

Couple of hands-on pocs with quarkus including resteasy reactive,kafka streams,kafka producers etc. were done to evaulate performance.

Let us talk about the biggest fundamental difference as there are many. Quarkus is not a mere framework approach. It is a platform approach to solving problems in a reactive fashion. Now let us look at a trusted public benchmark site i.e. -> https://www.techempower.com/benchmarks/ . Let us compare a Reactive Spring based JDBC application vs a Reactive Quarkus based application. Both use postgres db.

Note: Higher the number the better.

Spring WebFlux With Pgclient Performance

Quarkus With Pgclient Performance

There is a 10x difference inspite of being both reactive.

Why? Let us deep dive into details.

As i told quarkus is not a just a mere framework approach. To make sure you get performance and memory footprint to likes of golang, all famous db drivers are vertically integrated with vertx event loop threadpool (that is what quarkus uses underneath).

Basically the whole async definition is rewritten by quarkus by essentially not using any other hidden threadpool. Everything vertically integrates with vertx event pool.

Other frameworks/libs which simply handover the request to another threadpool will never be able to achieve similar performance and memory utilization.

Remember in java it is incredibly important not to use another threadpool/thread as the minimum stack size is 1 mb for each thread and there is a negative performance overhead when context switching.

Also, remember distributive computing frameworks like Apache Spark, flink etc use only 2x amount of threads where x is number of cpu cores alloted in your application. Even the Java Fork/Join api works in the same fashion.

This means instead of using ton of threads, quarkus brings same performance by sticking to strong fundamentals of cores to threads ratio.

The second biggest difference that

all annotations in quarkus do not use reflections which have a bad reputation for performance like spring especially in native mode with graalvm.

Please refer: https://dzone.com/articles/think-twice-before-using-reflection to understand why ?

The third fundamental difference is incredible startup time and memory overhead in quarkus for native mode compared to spring in native mode.

Why is that? What is happening underneath?

The central idea behind Quarkus is to do at build-time what traditional frameworks do at runtime: configuration parsing, classpath scanning, feature toggle based on classloading, and so on.

Quarkus Native application only contains the classes used at runtime out of ton of classes mentioned in your pom file. How and Why?

Process in Quarkus: In traditional frameworks, all the classes required to perform the initial application deployment hang around for the application’s life, even though they are only used once. With Quarkus, they are not even loaded into the production JVM!

During the build-time processing, it prepares the initialization of all components used by your application.

Consequence: It results in less memory usage and faster startup time as all metadata processing has already been done.

Refer: https://quarkus.io/vision/container-first for more in depth information how native builds in quarkus are way ahead in terms to spring native.

Kudos to Quarkus for redefining the future of java.

So yes obviously , QUARKUS is the way forward.

Still not convinced on why to use quarkus? Any queries? Comment here! if want to have a detailed discussion head over to the zulip channel mentioned below.

Kudos to Clement Escoffier (https://github.com/cescoffier) and Georgios Andrianakis(https://github.com/geoand) for explaining clearly the fundamentals of quarkus.

Also, Head over to https://quarkusio.zulipchat.com/login/ if you are looking to learn quarkus and fundamentally change the operating cost and performance of your existing and future applications.

References for Quarkus: https://www.youtube.com/channel/UCaW8QG_QoIk_FnjLgr5eOqg https://developers.redhat.com/courses/quarkus -> (These are free and do not even require registration)

References for POCs done on quarkus: https://github.com/JayGhiya/QuarkusExperiments/tree/initial_version_v1

Insights from POCS: 5x-8x lower memory footprint and higher performance to their traditional java counterparts and 30%-50% less code required.

Jay Ghiya
  • 424
  • 5
  • 16
  • Is there an entry for spring using r2dbc? – Adam Bickford Sep 08 '21 at 21:05
  • @AdamBickford - yes r2dbc looks improvement from jdbc spec in terms of being truly reactive for all sql dbs. But looking at benchmarks in terms of memory,throughput,latency - Quarkus still outsmarts with r2dbc - https://technology.amis.nl/software-development/performance-and-tuning/performance-of-relational-database-drivers-r2dbc-vs-jdbc/ . Also, Quarkus with Agroal and vertx driver should give more performance with less memory though i do not have exact numbers. One thing to keep in mind is Quarkus provides reactive drivers for the entire ecosystem be it nosql ,kafka etc. So, it wins! – Jay Ghiya Sep 09 '21 at 16:47
  • 2
    Quarkus has reactive database access, but it is based on Vertx, not r2dbc. These drivers are very mature and battle-hardened. Moreover, Quarkus integrates with Hibernate Reactive (on top of the Vertx layer) to provide even easier support for reactive database access. – geoand Sep 09 '21 at 16:56
  • Also Look for Max Rydahl Andersen's thread on innovative features of quarkus that i missed. -> https://threadreaderapp.com/thread/1436260001966919680.html ! – Jay Ghiya Sep 10 '21 at 18:17
  • This article clearly explains SpringBoot or Quarkus: Which framework is best for your project? https://blog.devgenius.io/springboot-or-quarkus-which-framework-is-best-for-your-project-2e448f9e9515 – vinod_vh Dec 18 '22 at 10:35