🍣

QuarkusのRESTサービス(JSON)をJARとNative Imageで実行してみた

2021/11/03に公開

QuarkusのRESTサービス(JSON)をJARとNative Imageで実行してみました。

起動時間についてポイント

JARの場合

  • JARの生成時間 : 10.309秒
  • 起動時間 : 0.893秒

Native Imageの場合

  • Native Imageの生成時間 : 1:45分 ※生成に時間がかかる...
  • 起動時間 : 0.307秒 ※起動は高速!!!

前提条件

JARで実行してみる

JARファイルの生成

$ ~/app/quarkus/quarkus-samples/rest-json-sample
$ ./mvnw package
[INFO] Scanning for projects...
・・・省略・・・
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ rest-json-sample ---
[INFO] Building jar: /Users/tack/app/quarkus/quarkus-samples/rest-json-sample/target/rest-json-sample-1.0.0-SNAPSHOT.jar
[INFO] 
[INFO] --- quarkus-maven-plugin:2.4.0.Final:build (default) @ rest-json-sample ---
[INFO] [org.jboss.threads] JBoss Threads version 3.4.2.Final
[INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 1012ms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  10.309 s
[INFO] Finished at: 2021-11-03T02:26:04+09:00
[INFO] ------------------------------------------------------------------------

JARファイルの確認

$ ls -la target/rest-json-sample-1.0.0-SNAPSHOT.jar
-rw-r--r--  1 tack  staff  7657 11  3 02:26 target/rest-json-sample-1.0.0-SNAPSHOT.jar

JARファイルの実行

$ java -jar target/quarkus-app/quarkus-run.jar
__  ____  __  _____   ___  __ ____  ______ 
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ 
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \   
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/   
2021-11-03 02:34:17,698 INFO  [io.quarkus] (main) rest-json-sample 1.0.0-SNAPSHOT on JVM (powered by Quarkus 2.4.0.Final) started in 0.893s. Listening on: http://0.0.0.0:8080
2021-11-03 02:34:17,706 INFO  [io.quarkus] (main) Profile prod activated. 
2021-11-03 02:34:17,706 INFO  [io.quarkus] (main) Installed features: [cdi, resteasy, resteasy-jackson, smallrye-context-propagation, vertx]

RESTサービス(JSON)の確認

$ curl -s http://localhost:8080/pets
[{"name":"ムギ","description":"犬:トイプードル"},{"name":"サクラ","description":"犬:チワワ"},{"name":"ハッピー","description":"犬:ミックス犬"}]% 

Native Imageで実行してみる

Native Imageの生成

$ ./mvnw package -Pnative 
[INFO] Scanning for projects...
・・・省略・・・
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:45 min
[INFO] Finished at: 2021-11-03T02:37:37+09:00
[INFO] ------------------------------------------------------------------------

Native Imageファイルの確認

$ ls -la target/rest-json-sample-1.0.0-SNAPSHOT-runner
-rwxr-xr-x  1 tack  staff  48406040 11  3 02:37 target/rest-json-sample-1.0.0-SNAPSHOT-runner

Native Imageファイルの実行

$ target/rest-json-sample-1.0.0-SNAPSHOT-runner
__  ____  __  _____   ___  __ ____  ______ 
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ 
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \   
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/   
2021-11-03 02:41:01,462 INFO  [io.quarkus] (main) rest-json-sample 1.0.0-SNAPSHOT native (powered by Quarkus 2.4.0.Final) started in 0.307s. Listening on: http://0.0.0.0:8080
2021-11-03 02:41:01,464 INFO  [io.quarkus] (main) Profile prod activated. 
2021-11-03 02:41:01,464 INFO  [io.quarkus] (main) Installed features: [cdi, resteasy, resteasy-jackson, smallrye-context-propagation, vertx]

RESTサービス(JSON)の確認

$ curl -s http://localhost:8080/pets
[{"name":"ムギ","description":"犬:トイプードル"},{"name":"サクラ","description":"犬:チワワ"},{"name":"ハッピー","description":"犬:ミックス犬"}]% 

以上です🎉

Discussion