This service application is based on the 'Quarkus demo: Hibernate ORM with Panache and RESTEasy'
This is a minimal service exposing a couple of endpoints over REST
While the code is surprisingly simple, under the hood this is using:
- RESTEasy to expose the REST endpoints
- Hibernate ORM with Panache to perform the CRUD operations on the database
- A PostgreSQL database; see below to run one via Docker
- ArC, the CDI inspired dependency injection tool with zero overhead
- The high performance Agroal connection pool
- Infinispan based caching__
- All safely coordinated by the Narayana Transaction Manager
To compile and run this demo you will need:
- GraalVM
1.0 rc12
(only for native build) - Apache Maven
3.5.3+
In addition, you will need either a PostgreSQL database, or Docker to run one.
If you don't have GraalVM installed, you can download it here:
https://github.com/oracle/graal/releases
Installing GraalVM is very similar to installing any other JDK:
just unpack it, add it to your path, and point the JAVA_HOME
and GRAALVM_HOME
environment variables to it.
You should then use this JDK to run the Maven build.
After having set GraalVM as your JVM, launch the Maven build on the checked out sources of this demo:
mvn package
First we will need a PostgreSQL database; you can launch one easily if you have Docker installed:
docker run --ulimit memlock=-1:-1 -it --rm=true --memory-swappiness=0 --name shoes-db -e POSTGRES_USER=shoes -e POSTGRES_PASSWORD=shoes -e POSTGRES_DB=shoes-db -p 5432:5432 postgres:10.5
Alternatively you can setup a PostgreSQL instance in any another way.
The connection properties of the Agroal datasource are configured in the standard Quarkus configuration file, which you will find in
src/main/resources/application.properties
.
To run the application in interactive mode (developer mode):
mvn compile quarkus:dev
In this mode you can make changes to the code and have the changes immediately applied, by just refreshing your browser.
Hot reload works even when modifying your JPA entities.
Try it! Even the database schema will be updated on the fly.
When you're done playing with "dev-mode" you can run it as a standard Java application.
First compile it:
mvn package
Then run it:
java -jar ./target/shoes-catalogue-application-1.0-SNAPSHOT-runner.jar
Have a look at how fast it boots.
Or measure total native memory consumption...
This same demo can be compiled into native code: no modifications required.
This implies that you no longer need to install a JVM on your production environment, as the runtime technology is included in the produced binary, and optimized to run with minimal resource overhead.
Compilation will take a bit longer, so this step is disabled by default;
let's build again by enabling the native
profile:
mvn package -Dnative
After getting a cup of coffee, you'll be able to run this binary directly:
./target/shoes-catalogue-application-1.0-SNAPSHOT-runner
Please brace yourself: don't choke on that fresh cup of coffee you just got.
Now observe the time it took to boot, and remember: that time was mostly spent to generate the tables in your database and import the initial data.
Next, maybe you're ready to measure how much memory this service is consuming.
N.B. This implies all dependencies have been compiled to native; that's a whole lot of stuff: from the bytecode enhancements that Panache applies to your entities, to the lower level essential components such as the PostgreSQL JDBC driver, the Undertow webserver.
Navigate to:
http://localhost:8080/index.html
Have fun!!!