æè¿ã§ã¦ãããã¬ã¼ã ã¯ã¼ã¯ãHelidonãMicronautãQuarkusã®ã¯ã¤ãã¯ã¹ã¿ã¼ããNative-Imageãã¾ã¨ãã¦è©¦ãã¾ãããã
æºå
SDKMANã¤ã³ã¹ãã¼ã«
ä»åã¯SDKMANã§ç°å¢ãä½ã£ã¦ããã¾ãã
https://sdkman.io/
ã³ãã³ãã©ã¤ã³ã§æ¬¡ã®ã³ãã³ããå®è¡ãã¾ããWindowsã®å ´åã¯CygwinãWSLã§ã
$ curl -s "https://get.sdkman.io" | bash
ã¿ã¼ããã«ãéããªããã次ã®ã³ãã³ããå®è¡ããã¨SDKMANãæå¹ã«ãªãã¾ãã
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
JDKã¤ã³ã¹ãã¼ã«
ä»åã¯native-imageã¾ã§ä½¿ãã®ã§GraalVMã使ã£ã¦ããã¾ãããã
$ sdk use java 19.1.0-grl
native-imageã®æºåãè¡ãã¾ããCygwinã§ã¯native-imageã¯ãã³ãã«ããã¦ããã®ã§ä¸è¦ã§ããããã¾ã®ã¨ãã3ã¤ã®ãã¬ã¼ã ã¯ã¼ã¯ã®ãã¤ãã£ãåãã§ãã¦ã¾ããã
$ gu install native-image
Mavenã¤ã³ã¹ãã¼ã«
Helidonã¨Quarkusã§ã¯Mavenã使ãã®ã§ã¤ã³ã¹ãã¼ã«ãã¦ããã¾ãã
$ sdk install maven
Helidon
Helidonã¯Oracleã®WebLogicãã¼ã ãéçºãã¦ãããã¬ã¼ã ã¯ã¼ã¯ã§ãã
https://helidon.io/
ç¬èªAPIã使ãSEã¨MicroProfileã使ãMPãããã¾ãããç¾æç¹ã§native-imageã«å¯¾å¿ãã¦ããã®ã¯SEã®ã¿ãªã®ã§ãããã§ã¯SEã使ãã¾ãã
ããã¸ã§ã¯ãä½æ
archetypeããä½æãã¾ãããããããå ¥åããã®ã¯é¢åãªã®ã§ãåè£ããé¸æãã¾ãã
$ mvn archetype:generate
ããããåè£ãã§ãã®ã§ãçµãè¾¼ã¿ã¾ãã
... 2450: remote -> xyz.luan.generator:xyz-gae-generator (-) 2451: remote -> xyz.luan.generator:xyz-generator (-) Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 1387:
ããã§helidon
ã¨å
¥åããã¨ï¼ã¤ã«çµããã¾ãã
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 1387: helidon Choose archetype: 1: remote -> io.helidon.archetypes:helidon-quickstart-mp (Quickstart archetype for Helidon MP) 2: remote -> io.helidon.archetypes:helidon-quickstart-se (Quickstart archetype for Helidon SE) Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): :
2
ãå
¥åãã¦Helidon SEãé¸ã³ã¾ãã
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 2 Choose io.helidon.archetypes:helidon-quickstart-se version: 1: 0.9.0 ... 16: 1.1.1 17: 1.1.2 Choose a number: 17:
ãã®ã¾ã¾enterãããã¦ææ°ãé¸ã³ã¾ãã
ãã®å¾ãgroupId
ãartifactId
ãversion
ãpackage
ãå
¥åãã¾ããgroupId
ã¯çµç¹åãartifactId
ãããã¸ã§ã¯ãåã§ãã
Define value for property 'groupId': kis Define value for property 'artifactId': start-helidon Define value for property 'version' 1.0-SNAPSHOT: : Define value for property 'package' kis: : Confirm properties configuration: groupId: kis artifactId: start-helidon version: 1.0-SNAPSHOT package: kis Y: : y
artifactId
ã¨åãååã®ãã£ã¬ã¯ããªãã§ãã¦ããã®ã§ç§»åãã¦ããã¾ãã
$ cd start-helidon
ãã«ã
ãã«ãã¯Mavenã§ã
$ mvn package
å®è¡
targetã«artifactIdã¨åãååã®jarãã¡ã¤ã«ãã§ãã¦ãã¦ããã®jarãã¡ã¤ã«ãå®è¡ããã°ãµã¼ãã¼ãèµ·åãã¾ãã
$ java -jar target/start-helidon.jar [DEBUG] (main) Using Console logging 2019.07.15 07:35:48 INFO io.helidon.webserver.NettyWebServer Thread[main,5,main]: Version: 1.1.2 2019.07.15 07:35:48 INFO io.helidon.webserver.NettyWebServer Thread[nioEventLoopGroup-2-1,10,main]: Channel '@default' started: [id: 0x8985c83f, L:/0:0:0:0:0:0:0:0:8080] WEB server is up! http://localhost:8080/greet
ã¡ãã»ã¼ã¸ã©ããhttp://localhost:8080/greetã«ã¢ã¯ã»ã¹ããã¨JSONãè¿ã£ã¦ãã¾ãã
ãã¤ãã£ãå
native-image
ãããã¡ã¤ã«ã§Mavenãã«ãããã¨ãã¤ãã£ãåã§ãã¾ãã
$ mvn -Pnative-image package
1åã»ã©å¾
ã¤ã¨ãtarget
ãã£ã¬ã¯ããªã«å®è¡ãã¡ã¤ã«ãã§ãã¾ãã
$ target/start-helidon 2019.07.15 07:42:14 INFO io.helidon.webserver.NettyWebServer !thread!: Version: 1.1.2 2019.07.15 07:42:14 INFO io.helidon.webserver.NettyWebServer !thread!: Channel '@default' started: [id: 0xb59ae091, L:/0:0:0:0:0:0:0:0:8080] WEB server is up! http://localhost:8080/greet
Micronaut
Microanutã¯Grailsãä½ã£ã¦ããObject Computing社ãéçºãã¦ãããã¬ã¼ã ã¯ã¼ã¯ã§ããç¬èªAPIã使ã£ã¦ãã¦ãAPIã®ä½¿ãããããããã¥ã¡ã³ãã®ãããããããé
åãKotlinãGroovyã«ã対å¿ãã¦ãã¾ãã
https://micronaut.io/
ããã¸ã§ã¯ãä½æ
ããã¸ã§ã¯ãä½æã«ã¯Micornautã®ã³ãã³ãã使ãã¾ãããããSDKMANã§ã¤ã³ã¹ãã¼ã«ã§ãã¾ãã
$ sdk install micronaut
mn
ã³ãã³ãã§ããã¸ã§ã¯ããçæãã¾ãã
$ mn create-app start-mn Resolving dependencies.. | Generating Java project... | Application created at /home/naoki/starts/start-mn
ããã¸ã§ã¯ãåã®ãã£ã¬ã¯ããªã«ç§»åãã¾ãã
$ cd start-mn
ã³ã³ããã¼ã©ã¼ã¯ä½æãããªãã®ã§ãmnã³ãã³ãã§ã³ã³ããã¼ã©ã¼ãä½æãã¾ãã
$ mn create-controller MyController
src/main/java/start/mn/MyController.javaãä½æãããã®ã§å°ãç·¨éãã¾ãã
package start.mn; import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; @Controller // ãã¹ãæ¶ãã¦ãã public class MyController { @Get(produces="TEXT/PLAIN") // åºåã¡ãã£ã¢ã¿ã¤ããæå® public String hello() { // æ»ãå¤ãStringã« return "Hello"; // ã¡ãã»ã¼ã¸ãè¿ã } }
ãã«ã
ãã«ãã¯Gradleã使ãã¾ãã
$ ./gradlew build > Task :compileJava Note: Creating bean classes for 1 type elements BUILD SUCCESSFUL in 8s 10 actionable tasks: 10 executed
å®è¡
build/libs
ã«å®è¡å¯è½jarãä½æããã¦ããã®ã§å®è¡ããã¨ãµã¼ãã¼ãèµ·åãã¾ãã
$ java -jar build/libs/start-mn-0.1-all.jar 07:57:32.751 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 1496ms. Server Running: http://localhost:8080
http://localhost:8080ã«ã¢ã¯ã»ã¹ããã¨ã¡ãã»ã¼ã¸ã表示ããã¾ãã
â» 8/13è¿½è¨ 1.2ããstart-mn-0.1.jarãããªãstart-mn-0.1-all.jarã«ãªã£ãï¼
ãã¤ãã£ãå
Micronautã§ã¯ç¹å¥ãªãã¤ãã£ãåã³ãã³ãã¯ç¨æããã¦ããªãã®ã§ãnative-image
ã³ãã³ããç´æ¥ä½¿ãã¾ãã
$ native-image -jar build/libs/start-mn-0.1-all.jar
ã«ã¬ã³ããã£ã¬ã¯ããªã«å®è¡ãã¡ã¤ã«ãä½æããã¾ãã
$ ./start-mn-0.1-all 08:03:09.159 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 131ms. Server Running: http://localhost:8080
Quarkus
Quarkusã¯Red Hatãéçºãã¦ãããã¬ã¼ã ã¯ã¼ã¯ã§ãMicroProfileããã¼ã¹ã«ãã¦ãã¾ãã
https://quarkus.io/
ããã¸ã§ã¯ãä½æ
ããã¸ã§ã¯ãä½æã«ã¯Mavenã使ãã¾ãããé常ã®archetypeã§ã¯ãªãç¬èªãã©ã°ã¤ã³ã使ãã¾ãã
$ mvn io.quarkus:quarkus-maven-plugin::create
groupId
ãartifactId
ã®ã»ãã«RESTãªã½ã¼ã¹ãä½ããããããã®ã§ãy
ã«ãã¦ããã¾ãã
$ mvn io.quarkus:quarkus-maven-plugin::create [INFO] Scanning for projects... [INFO] [INFO] ------------------< org.apache.maven:standalone-pom >------------------- [INFO] Building Maven Stub Project (No POM) 1 [INFO] --------------------------------[ pom ]--------------------------------- [INFO] [INFO] --- quarkus-maven-plugin:0.19.1:create (default-cli) @ standalone-pom --- Set the project groupId [org.acme.quarkus.sample]: kis Set the project artifactId [my-quarkus-project]: start-quarkus Set the project version [1.0-SNAPSHOT]: Do you want to create a REST resource? (y/n) [no]: y Set the resource classname [kis.HelloResource]: Set the resource path [/hello]: Creating a new project in /home/naoki/starts/start-quarkus ...
ãã«ã
ãã«ãã¯Mavenã§ãã¤ãã©ãã
$ mvn package
å®è¡
target
ãã£ã¬ã¯ããªã«å®è¡ãã¡ã¤ã«ãã§ããã®ã§ãjavaã³ãã³ãã§å®è¡ãããã¨ãã§ãã¾ãã
$ java -jar target/start-quarkus-1.0-SNAPSHOT-runner.jar 2019-07-15 08:25:07,637 INFO [io.quarkus] (main) Quarkus 0.19.1 started in 0.878s. Listening on: http://[::]:8080 2019-07-15 08:25:07,656 INFO [io.quarkus] (main) Installed features: [cdi, resteasy]
http://localhost:8080/hello ã«ã¢ã¯ã»ã¹ããã¨ã¡ãã»ã¼ã¸ã表示ããã¾ãã
Quarkusã®å ´åãMavenã§å®è¡ãããã¨ã§ãªã¼ããªãã¼ãã£ã³ã°ãæå¹ã«ãªãã®ã§ãéçºæã¯ãã¡ãã使ãã»ãã便å©ã§ãã
$ mvn quarkus:dev
ãã¤ãã£ãå
Quarkusã®ãã¤ãã£ãåã¯ãnative
ãããã¡ã¤ã«ãæå®ãã¦ãã«ããã¾ãã
$ mvn -Pnative package
1åã¡ããå¾
ã¤ã¨target
ãã£ã¬ã¯ããªã«å®è¡ãã¡ã¤ã«ãã§ããã®ã§ããããå®è¡ããã¨ãµã¼ãã¼ãèµ·åãã¾ãã
$ target/start-quarkus-1.0-SNAPSHOT-runner 2019-07-15 08:31:53,378 INFO [io.quarkus] (main) Quarkus 0.19.1 started in 0.016s. Listening on: http://[::]:8080 2019-07-15 08:31:53,379 INFO [io.quarkus] (main) Installed features: [cdi, resteasy]
èµ·åæéãã¡ã¢ãªã®æ¯è¼
ä»åã¯WSLä¸ã®Ubuntuã§ã®èµ·åæéã¨å©ç¨ã¡ã¢ãªãæ¯è¼ãã¦ã¿ã¾ãã
Helidonã§ã¯èµ·åæéã表示ããã¦ããªãã®ã§ã次ã®ãããªè¡¨ç¤ºã³ã¼ãã追å ãã¦ããã¾ãã
System.out.println(ManagementFactory.getRuntimeMXBean().getUptime());
èµ·åæéã¯æ¬¡ã®ããã«ãªãã¾ãã
GraalVM JDK | OpenJDK 12.0.1 | native-image | |
---|---|---|---|
Helidon | 864ms | 715ms | 16ms |
Micronaut | 1552ms | 1387ms | 109ms |
Quarkus | 819ms | 720ms | 15ms |
ãã¤ãã£ãåããã¨å§åçã«èµ·åãéããªã£ã¦ã¾ãããGraalVMãããOpenJDK 12ã®ã»ããããªãéãã§ãããGraalã¨C2ã®éãã ã¨æãã¾ããGraalã§ã¯Javaã§æ¸ããã¦ããGraalèªä½ãJITããã®ã«æéããããã®ã§èµ·åã¯é
ããªããã¡ã§ãã
ã¡ã¢ãªä½¿ç¨éã¯æ¬¡ã®ãããªæãã«ã
GraalVM JDK | OpenJDK 12.0.1 | native-image | |
---|---|---|---|
Helidon | 233.7MB | 64.9MB | 7.4MB |
Micronaut | 344.6MB | 95.2MB | 15.0MB |
Quarkus | 246.6MB | 81.3MB | 6.9MB |
ããããã¤ãã£ãåããã¨ã¡ã¢ãªä½¿ç¨éãæ¿æ¸ãã¦ã¾ãããGraalVMãããOpenJDK 12ã®ã»ããå°ãªããªã£ã¦ã¾ããGraalãã¡ã¢ãªã使ã£ã¦ããã§ãããã