开发模式与生产应用程序有何不同
This document explains how the dev mode in Quarkus differs from a production application.
Architectural differences
Feature sets aside, the Quarkus application that is run under dev mode differs architecturally from the production application (i.e. the one that is run using java -jar …
).
In dev mode, Quarkus uses a ClassLoader hierarchy (explained in detail here) that enables the live reload of user code without requiring a rebuild and restart of the application.
In a production application, the aforementioned class loading infrastructure is entirely absent - there is a single, purpose built ClassLoader that loads (almost) all classes and dependencies.
Dev-mode features
In keeping with the mantra of providing developer joy, Quarkus provides a host of features when dev mode is enabled. The most important features are:
实时重载
This mightily important feature needs no introduction and has already been mentioned in the architectural differences section.
开发用户界面
Quarkus provides a very useful UI accessible from the browser at /q/dev-ui
. This UI allows a developer to see the state of the application, but
also provides access to various actions that can change that state (depending on the extensions that are present).
Examples of such operations are:
-
Changing configuration values
-
Running Database migration scripts
-
Clearing of caches
-
Running scheduled operations
-
Building a container
A new Dev UI has been implemented in Quarkus 3.x. Not all the features are available yet. You can still access the previous version of the Dev UI using: http://localhost:8080/q/dev-ui/. |
Error pages
In an effort to make development errors very easy to diagnose, Quarkus provides various detailed error pages when running in dev mode.
Database import scripts
The quarkus-hibernate-orm
extension will run the import.sql
script in src/main/resources
when Quarkus is running in dev mode. More details can be found here.
开发服务
When testing or running in dev mode Quarkus can even provide you with a zero config database out of the box, a feature we refer to as Dev Services. More information can be found here.
Swagger UI
The quarkus-smallrye-openapi
extension will expose the Swagger UI when Quarkus is running in dev mode. Additional information can be found here.
GraphQL UI
The quarkus-smallrye-graphql
extension will expose the GraphQL UI when Quarkus is running in dev mode. More details can be found here.
Health UI
The quarkus-smallrye-health
extension will expose the Health UI when Quarkus is running in dev mode. This section provides additional information.
Mock mailer
The quarkus-mailer
extension will enable an in-memory mock mail server when Quarkus is running in dev mode. See this for more details.
gRPC
-
The gRPC Reflection Service is enabled in dev mode by default. That lets you use tools such as
grpcurl
. In production mode, the reflection service is disabled. You can enable it explicitly usingquarkus.grpc-server.enable-reflection-service=true
. -
In dev mode,
quarkus.grpc.server.instances
has no effect.
Performance implications
In dev mode, minimizing the runtime footprint of the application is not the primary objective (although Quarkus still starts plenty fast and consumes little memory) - the primary objective is enabling developer joy. Therefore, many more classes are loaded and build time operations also take place every time a live-reload is performed.
In contrast, in a production application the main objective for Quarkus is to consume the least amount of memory and startup in the smallest amount of time. Thus, when running the production application, build time operations are not performed (by definition) and various infrastructure classes needed at build time are not present at all at runtime. Furthermore, the purpose built ClassLoader that comes with the fast-jar package type ensures that class lookup is done as fast as possible while also keeping the minimum amount of jars in memory.
Since optimal performance is never an objective of dev mode, in the interest of improving startup time, the JVM’s C2 compiler is disabled in dev mode. |
Security implications
Perhaps the most important reason why dev mode applications should not be run in production is that the dev mode allows reading information that could be confidential (via the Dev-UI) while also giving access to operations that could be destructive (either by exposing endpoints that should not be available in production application or via the Dev-UI).
Native executable
When a native executable is created (explained in detail here), it is always built from a production application.