redhat-developer-demos / quarkus-petclinic

Apache License 2.0
18 stars 50 forks source link

[FEATURE REQUEST] Use H2 as database for smallest possible footprint - did I do this right? #11

Closed ksilz closed 1 year ago

ksilz commented 1 year ago

For my conference talks at JavaLand 2023 and JAX Mainz 2023, I want to compare startup time & memory consumption of the Spring Boot PetClinic with the Quarkus PetClinic. Right now, that's not an apples-to-apples comparison, as Spring uses H2 out of the box and Quarkus does not.

So I added H2 with mvn quarkus:add-extension -Dextensions="jdbc-h2" and changed the application.properties as below. Then I ran mvn package -DskipTests=true. The resulting quarkus-petclinic-1.0.0-SNAPSHOT-runner.jar uses 280M of memory on my M1 Mac with OpenJDK 15, as shown by top -pid [process id] -stats mem.

Is this the smallest Quarkus Project I can get? If not, what else do I need to change?

quarkus.datasource.db-kind=h2
quarkus.datasource.username=username-default
quarkus.datasource.jdbc.url=jdbc:h2:mem:default
quarkus.package.type=uber-jar

#%prod.quarkus.datasource.username=developer
#%prod.quarkus.datasource.password=developer
#%prod.quarkus.datasource.jdbc.url=jdbc:postgresql://postgresql:5432/mydb
quarkus.datasource.jdbc.min-size=5
quarkus.datasource.jdbc.max-size=15

%dev.quarkus.hibernate-orm.sql-load-script=import.sql
%prod.quarkus.hibernate-orm.sql-load-script=import.sql

quarkus.hibernate-orm.log.sql=true
quarkus.hibernate-orm.database.generation=drop-and-create

quarkus.container-image.group=rhdevelopers
quarkus.container-image.registry=quay.io
quarkus.container-image.tag=1.0.0

quarkus.kubernetes.service-type=load-balancer

quarkus.http.enable-compression=true
quarkus.http.enable-decompression=true
geoand commented 1 year ago

You would like likely want to have a Maven profile which would determine which DB driver is used. That way you will ensure that the built artifact never has more runtime footprint than necessary.

ksilz commented 1 year ago

@geoand If I understand you correctly, you're saying that if I build the app as described above, then it'd be bigger than it should be? Because the Postgres drivers are still included?

geoand commented 1 year ago

Exactly.

The difference will likely be negligible, but still, if you are looking for the best way, Maven profiles is the way to go.

Although, I would question why one would need to use H2 at all, since using Postgres is a zero configuration task with Quarkus

On Thu, Jan 26, 2023, 01:17 Karsten Silz @.***> wrote:

@geoand https://github.com/geoand If I understand you correctly, you're saying that if I build the app as described above, then it'd be bigger than it should be? Because the Postgres drivers are still included?

— Reply to this email directly, view it on GitHub https://github.com/redhat-developer-demos/quarkus-petclinic/issues/11#issuecomment-1404348808, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBMDP7I5PPOHULQJU5N4Z3WUGYAZANCNFSM6AAAAAAUF74BE4 . You are receiving this because you were mentioned.Message ID: @.***>

ksilz commented 1 year ago

@geoand Thank you for the explanation!

The reason for H2 is that my talk will include a link to the Quarkus PetClinic repo and instructions on how to run & build it. And there, it's always easier if it's self-contained, without external dependencies. I will probably also note how to connect to Postgres, but not explain how to set up Postgres.

I may test the PetClinic with the Postgres driver for the talk, as this is the most realistic result.