On quarkus -- environment configuration

Basic concepts

What is quarkus

Quarkus is an open source cloud native framework integrating k8s, which is used to create k8s native references adapted to GraalVM and OPenJDK HotSpot. Here are two new nouns: GraalVM and Open JDK HotSpot. Let's take a look at these two things first:
One sentence summary: refers to HotSpot VM, which is a virtual machine built in Sun JDK and OpenJDK. It has this name because it uses hotspot code detection technology.

Detailed introduction
mention HotSpot VM,Believe all Java Programmers know that it is Sun JDK and OpenJDK The virtual machine in is also the most widely used one at present Java Virtual machine. But not everyone knows that this virtual machine, which looks "pure blood" at present, was not originally created by Sun Developed by a company called“ Longview Technologies"Even this virtual machine was not originally designed for Java Language, which comes from Strongtalk VM, A considerable number of technologies in this virtual machine come from a support Self Language implementation "achieve C Language 50%The virtual machine designed for the goal of "execution efficiency", Sun The company noticed that the virtual machine was JIT There are many excellent concepts and practical effects in compilation, which were acquired in 1997 Longview Technologies The company thus obtained HotSpot VM. 

HotSpot VM Both inherited Sun The advantages of the previous two commercial virtual machines (such as accurate memory management mentioned earlier) also have many new technical advantages, such as HotSpot It refers to its hot code detection technology (actually two) VM Basically independent products of the same period, HotSpot Earlier, HotSpot From the beginning, it was the exact formula GC, and Exact VM There are also and HotSpot Almost the same hot spot detection Exact VM and HotSpot VM Which becomes Sun Main supported VM Products, in Sun There have been debates within the company, HotSpot beat Exact It's not a technical victory, HotSpot VM The hot code detection capability of can find the code with the most compilation value through the execution counter, and then notify JIT The compiler compiles in method units. If a method is called frequently, or there are many valid cycles in the method, standard compilation and standard compilation will be triggered respectively OSR(Stack replacement) compilation action. Through the proper cooperation between the compiler and the interpreter, the balance can be achieved between the optimized program response time and the optimal execution performance, and the program can be executed without waiting for the output of local code. The time pressure of immediate compilation is also relatively reduced, which helps to introduce more code optimization technologies and output higher quality local code . 

In 2006 JavaOne At the conference, Sun The company announced that it would eventually Java Open source, and in the following year, will continue to JDK Various parts of (including, of course) HotSpot VM)stay GPL The source code is disclosed under the protocol, and on this basis, a OpenJDK. So, HotSpot VM It became Sun JDK and OpenJDK Two achieve extremely close JDK Common virtual machine for the project.

In 2008 and 2009, Oracle The company acquired BEA Company and Sun Company, so Oracle It has two excellent models at the same time Java Virtual machine: JRockit VM and HotSpot VM.  Oracle The company announced that it would release in the near future (about JDK 8 The integration of these two virtual machines will be completed to complement each other's advantages. The integration method is basically HotSpot Based on, transplantation JRockit Excellent features, such as using JRockit Garbage collector and MissionControl Services, using HotSpot of JIT Compiler and hybrid runtime system.

One sentence summary: a cross language full stack virtual machine enhanced on the basis of HotSpot virtual machine can be used as "any language" The principle of the running platform is to convert the source code of these languages or the compiled intermediate format of the source code into an intermediate representation that can be accepted by Graal VM through the interpreter, and then uniformly optimize. The optimized languages can run in this virtual machine at the same time, so as to reduce the communication overhead of different languages.

GraalVM details
Graal VM By April 2018 Oracle Lab Release, officially known as“ Universal VM"And“ Polyglot VM",This is a HotSpot The cross language full stack virtual machine enhanced on the basis of virtual machine can be used as the running platform of "any language". Here, "any language" includes Java,Scala,Groovy,Kotlin Etc. Based Java The language on the virtual machine also includes C,C++,Rust Etc. Based LLVM Other languages like JavaScript,Ruby,Python and R Language, etc. Graal VM These programming languages can be mixed without additional cost. It supports the mixing of each other's interfaces and objects in different languages, as well as the use of written local library files in these languages.

Graal VM The basic working principle of is to integrate the source code of these languages (e.g JavaScript)Or intermediate format after source code compilation (e.g LLVM Bytecode) can be converted by the interpreter Graal VM Intermediate representation of acceptance( IR),For example, designing an interpreter specifically for LLVM The output bytecode is converted to support C and C++Language, this process is called "program specialization"( Specialized,Also often referred to as Partial Evaluation). Graal VM Provided Truffle Tool set to quickly build an interpreter for a new language, and use it to build an interpreter called Sulong High performance LLVM Bytecode interpreter.

From a more rigorous point of view, Graal VM It is the high-level language virtual machine corresponding to the physical computer in the real sense. The reason is that, like the instruction set of physical hardware, it is only related to machine characteristics rather than some high-level language characteristics. Oracle Labs Director of research Thomas Wuerthinger In acceptance InfoQ The interview said: "with Graal VM 1.0 We have proved that it is possible to have a high-performance multilingual virtual machine, and the best way to achieve this goal is not through similar methods Java Virtual machines and Microsoft CLR For some language running environments that are not good at speed, because Graal VM It can automatically optimize the intermediate representation of input, and can also perform real-time compilation and optimization at runtime. It is often used Graal VM The implementation can achieve better execution efficiency than the native compiler, such as Graal.js Better than Node.js,Graal.Python Better than CPtyhon,TruffleRuby Better than Ruby MRI,FastR Better than R Language, etc.

in the light of Java for, Graal VM It was HotSpot Born on the basis of, nature can be used as a complete set of conformity Java SE 8 standard Java Virtual machine to use. It is different from standard HotSpot The difference is mainly in the real-time compiler. Its execution efficiency and compilation quality are different from those of the standard version HotSpot There are also victories and defeats for each other. But now Oracle Labs And the latest research on real-time compilation technology done by research institutes in American universities have all been migrated to Graal VM The development potential is expected Java Language or HotSpot Virtual machines will really be replaced one day. From now on Graal VM Is one of the most promising candidates, and this revolution is likely to Java The user comes quietly without obvious feeling, Java All the software ecology in the world has not changed at all, but the position of No. 1 in the world has quietly changed.

Quarkus runs on k8s. It can deploy an optimized k8s application and quickly start and run new k8s instances.


graph LR A [scaffolding] B [start development mode] C [Code] D [test] E [package] F [deployment] A --> B --> C --> D --> E --> F


I use vscode. I can install the plug-in of Quarkus first, and then press F1 to find Quarkus: build a Quarkus project to complete the creation of scaffold.

There are four main core parts:

  1. src\main\docker
  2. src\main\java\org\acme JAX-RS(Java API for RESTful Web Services) resource
  3. src\test\java\org\acme test for JAX-RS
  4. src\main\resources static resources
    The contents in docker folder generally do not need to be modified. The meaning of the file is as follows:
  • Dockerfile.jvm builds containers that run Quarkus applications in JVM mode
  • Dockerfile.legacy-jar builds a container for running Quarkus applications in JVM mode
  • Dockerfile.multigrade one-stop construction of native application image
  • Dockerfile.native builds a container that runs Quarkus applications in native (no JVM) mode
  • Dockerfile.native-troubleshooting builds a troubleshooting container that runs Quarkus applications in native (no JVM) mode


Q: gradlew is used as the dependency management tool of the project, so the next command will use gradlew. For maven projects, you can use mvnw, but the command format will be different. You can refer to the help provided on the command line.

./gradlew quarkusDev // Turn on hot loading

The deployment port will be given in the deployment process. My port is 8080. Open localhost:8080 to see the following page, indicating that the deployment is successful


[1] GraalVM: Java in the era of microservices https://zhuanlan.zhihu.com/p/137836206

Posted on Fri, 03 Dec 2021 14:05:00 -0500 by sword