Calendrier de l'Avent Java 2019 C'est l'article du 24ème jour.
Je suis libre avant même Noël: rage: J'ai comparé les vitesses de démarrage simples de Spring Boot et Micronaut, qui sont des frameworks basés sur le langage JVM.
Spring est un cadre que tout le monde connaît, je vais donc omettre l'introduction
--Cadre pour microservices développé par OCI
Site officiel https://micronaut.io/
--Java / Groovy / Kotlin peut être utilisé comme langage de programmation --Le temps de compilation DI & AOP est adopté --GraalVM et NativeImage peuvent également être utilisés --CLI est fourni
MacBook Pro

SpringBoot v2.2.2.RELEASE
Micronaut 1.2.7
SpringBoot
python
@RestController
public class HelloController {
    @RequestMapping(value="/hello", method=RequestMethod.GET)
    public String hello() {
        return "Hello Spring";
    }
}
Démarrez Tomcat
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.2.RELEASE)
2019-12-23 14:29:46.247  INFO 73041 --- [           main] com.example.sphelloapp.DemoApplication   : Starting DemoApplication
2019-12-23 14:29:46.250  INFO 73041 --- [           main] com.example.sphelloapp.DemoApplication   : No active profile set, falling back to default profiles: default
2019-12-23 14:29:46.925  INFO 73041 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-12-23 14:29:46.935  INFO 73041 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-12-23 14:29:46.935  INFO 73041 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.29]
2019-12-23 14:29:46.984  INFO 73041 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-12-23 14:29:46.984  INFO 73041 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 695 ms
2019-12-23 14:29:47.105  INFO 73041 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-12-23 14:29:47.214  INFO 73041 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-12-23 14:29:47.216  INFO 73041 --- [           main] com.example.sphelloapp.DemoApplication   : Started DemoApplication in 1.233 seconds (JVM running for 1.556)
Lancement de la jetée
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.2.RELEASE)
2019-12-23 14:22:39.036  INFO 72942 --- [           main] c.e.sphelloappjetty.DemoApplication      : Starting DemoApplication
2019-12-23 14:22:39.038  INFO 72942 --- [           main] c.e.sphelloappjetty.DemoApplication      : No active profile set, falling back to default profiles: default
2019-12-23 14:22:39.651  INFO 72942 --- [           main] org.eclipse.jetty.util.log               : Logging initialized @1229ms to org.eclipse.jetty.util.log.Slf4jLog
2019-12-23 14:22:39.713  INFO 72942 --- [           main] o.s.b.w.e.j.JettyServletWebServerFactory : Server initialized with port: 8080
2019-12-23 14:22:39.716  INFO 72942 --- [           main] org.eclipse.jetty.server.Server          : jetty-9.4.24.v20191120; built: 2019-11-20T21:37:49.771Z; git: 363d5f2df3a8a28de40604320230664b9c793c16; jvm 1.8.0_232-20191009173705.graal.jdk8u-src-tar-gz-b07
2019-12-23 14:22:39.738  INFO 72942 --- [           main] o.e.j.s.h.ContextHandler.application     : Initializing Spring embedded WebApplicationContext
2019-12-23 14:22:39.739  INFO 72942 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 664 ms
2019-12-23 14:22:39.815  INFO 72942 --- [           main] org.eclipse.jetty.server.session         : DefaultSessionIdManager workerName=node0
2019-12-23 14:22:39.815  INFO 72942 --- [           main] org.eclipse.jetty.server.session         : No SessionScavenger set, using defaults
2019-12-23 14:22:39.816  INFO 72942 --- [           main] org.eclipse.jetty.server.session         : node0 Scavenging every 660000ms
2019-12-23 14:22:39.821  INFO 72942 --- [           main] o.e.jetty.server.handler.ContextHandler  : Started o.s.b.w.e.j.JettyEmbeddedWebAppContext@45f45fa1{application,/,[file:///private/var/folders/xk/q20_p4gd2xz1sfmtmngwjg380000gp/T/jetty-docbase.146795275059491819.8080/],AVAILABLE}
2019-12-23 14:22:39.822  INFO 72942 --- [           main] org.eclipse.jetty.server.Server          : Started @1400ms
2019-12-23 14:22:39.922  INFO 72942 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-12-23 14:22:40.036  INFO 72942 --- [           main] o.e.j.s.h.ContextHandler.application     : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-12-23 14:22:40.036  INFO 72942 --- [           main] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2019-12-23 14:22:40.040  INFO 72942 --- [           main] o.s.web.servlet.DispatcherServlet        : Completed initialization in 4 ms
2019-12-23 14:22:40.060  INFO 72942 --- [           main] o.e.jetty.server.AbstractConnector       : Started ServerConnector@37574691{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2019-12-23 14:22:40.062  INFO 72942 --- [           main] o.s.b.web.embedded.jetty.JettyWebServer  : Jetty started on port(s) 8080 (http/1.1) with context path '/'
2019-12-23 14:22:40.064  INFO 72942 --- [           main] c.e.sphelloappjetty.DemoApplication      : Started DemoApplication in 1.299 seconds (JVM running for 1.643)
(référence) Paramètres de démarrage de la jetée (gradle)
build.gradle
dependencies {
    compile('org.springframework.boot:spring-boot-starter-web') {
        exclude module: 'spring-boot-starter-tomcat'
    }
    compile('org.springframework.boot:spring-boot-starter-jetty')
}
Spring ne prend pas encore officiellement en charge Native Image (prévu pour prendre en charge 2Q 2020) La version expérimentale est sur github, alors vérifiez-la avec ceci (Tomcat uniquement, pas de Jetty) https://github.com/spring-projects-experimental/spring-graal-native
procédure
. / Build-feature.shspring-graal-native-samples / springmvc-tomcat. / Compile.sh (1 à 2 minutes)

target et assurez-vous que springmvc-tomcat est généré. / Springmvc-tomcatCeci termine la préparation côté ressort
Micronaut
HelloController.java
@Controller
public class HelloController{
    @Get(value="/hello", produces = MediaType.TEXT_PLAIN)
    public String index(){
        return "Hello Micronaut";
    }
}
Commencez
14:37:49.383 [main] INFO  io.micronaut.runtime.Micronaut - Startup completed in 985ms. Server Running: http://localhost:8080
Micronaut prend en charge Native Image en standard, mais vous pouvez en profiter en créant un projet dédié à Native Image.
$mn create-app hello-graal --features graal-native-imageHelloController.java./gradlew build$ native-image --no-server -cp build / libs / hello-graal-0.1-all.jar (1 à 2 minutes). / Hello-graalCeci complète la préparation côté Micronaut

--Il n'y a presque aucune différence dans JDK (11, 8, GraalVM JIT). ――Il y a une différence d'environ 300 ms entre les cadres, mais cela dépend des pensées et des cas individuels, que cela soit considéré comme grand ou petit. Dans le cas de l'auteur, la différence n'est pas particulièrement perceptible. --GraalVM AOT (Native Image) est extrêmement rapide.
Comme il s'agit cette fois d'une vérification avec une application simple, le résultat peut être différent dans une application complexe réelle, j'espère donc que vous ne pourrez le voir que comme référence. Si j'en ai l'occasion, j'essaierai de vérifier des frameworks tels que Helidon et Quarkus.