---
title: 組み込みTomcat, Jetty, Undertowの起動時間を比べてみた
tags: ["Java", "Jetty", "Spring Boot", "Tomcat", "Undertow"]
categories: ["Programming", "Java", "org", "springframework", "boot"]
date: 2014-11-22T07:39:59Z
updated: 2014-11-22T07:39:59Z
---

Spring Boot 1.2.RC2からついに[Undertowがサポートされた](http://spring.io/blog/2014/11/21/spring-boot-1-2-0-rc2-available-now)ので、使ってみた。
これでSpring Bootでは

* Tomcat
* Jetty
* Undertow

のどれかを組み込みサーバーとして使うことが出来る。

起動時間の差を調べてみよう。
[前にもやった](http://blog.ik.am/#/entries/281)が、Spring Bootのバージョンが上がったので、組み込みサーバーのバージョンが上がっている。


Spring MVCを抜いて、素のサーブレットが一個あるだけの状態でそれぞれ起動時間を計測した。10回やって最速だったものを貼っていく。(MBA 11-inch, Mid 2011)

サンプルコードは[こちら](https://blog.ik.am/api/v1/files/696b770d-120b-4070-800e-84ac4effcfff/servlet-sample.zip)。

#### Tomcat 8.0.15

``` bash
      .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::            (v1.2.0.RC2)

2014-11-22 16:07:24.517  INFO 7722 --- [           main] com.example.Application                  : Starting Application on saturn.local with PID 7722 (/Users/maki/git/servlet-sample/target/classes started by maki in /Users/maki/git/servlet-sample)
2014-11-22 16:07:24.570  INFO 7722 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4923ab24: startup date [Sat Nov 22 16:07:24 JST 2014]; root of context hierarchy
2014-11-22 16:07:25.873  INFO 7722 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080/http
2014-11-22 16:07:26.173  INFO 7722 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2014-11-22 16:07:26.175  INFO 7722 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.15
2014-11-22 16:07:26.294  INFO 7722 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2014-11-22 16:07:26.294  INFO 7722 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1727 ms
2014-11-22 16:07:26.409  INFO 7722 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'fooServlet' to [/foo]
2014-11-22 16:07:26.416  INFO 7722 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
2014-11-22 16:07:26.732  INFO 7722 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2014-11-22 16:07:26.788  INFO 7722 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080/http
2014-11-22 16:07:26.789  INFO 7722 --- [           main] com.example.Application                  : Started Application in 2.574 seconds (JVM running for 3.029)
```

#### Jetty 9.2.4.v20141103

``` bash
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::            (v1.2.0.RC2)

2014-11-22 16:06:14.918  INFO 7708 --- [           main] com.example.Application                  : Starting Application on saturn.local with PID 7708 (/Users/maki/git/servlet-sample/target/classes started by maki in /Users/maki/git/servlet-sample)
2014-11-22 16:06:14.967  INFO 7708 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2641e737: startup date [Sat Nov 22 16:06:14 JST 2014]; root of context hierarchy
2014-11-22 16:06:16.333  INFO 7708 --- [           main] e.j.JettyEmbeddedServletContainerFactory : Server initialized with port: 8080
2014-11-22 16:06:16.337  INFO 7708 --- [           main] org.eclipse.jetty.server.Server          : jetty-9.2.4.v20141103
2014-11-22 16:06:16.396  INFO 7708 --- [           main] /                                        : Initializing Spring embedded WebApplicationContext
2014-11-22 16:06:16.397  INFO 7708 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1433 ms
2014-11-22 16:06:16.571  INFO 7708 --- [           main] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'fooServlet' to [/foo]
2014-11-22 16:06:16.575  INFO 7708 --- [           main] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
2014-11-22 16:06:16.579  INFO 7708 --- [           main] o.e.jetty.server.handler.ContextHandler  : Started o.s.b.c.e.j.JettyEmbeddedWebAppContext@127a7a2e{/,null,AVAILABLE}
2014-11-22 16:06:16.579  INFO 7708 --- [           main] org.eclipse.jetty.server.Server          : Started @2647ms
2014-11-22 16:06:16.933  INFO 7708 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2014-11-22 16:06:17.012  INFO 7708 --- [           main] o.eclipse.jetty.server.ServerConnector   : Started ServerConnector@466276d8{HTTP/1.1}{0.0.0.0:8080}
2014-11-22 16:06:17.017  INFO 7708 --- [           main] .s.b.c.e.j.JettyEmbeddedServletContainer : Jetty started on port: 8080
2014-11-22 16:06:17.019  INFO 7708 --- [           main] com.example.Application                  : Started Application in 2.629 seconds (JVM running for 3.087)
```

#### Undertow 1.1.0.Final

``` bash
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::            (v1.2.0.RC2)

2014-11-22 16:13:08.863  INFO 7769 --- [           main] com.example.Application                  : Starting Application on saturn.local with PID 7769 (/Users/maki/git/servlet-sample/target/classes started by maki in /Users/maki/git/servlet-sample)
2014-11-22 16:13:08.913  INFO 7769 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@50d0686: startup date [Sat Nov 22 16:13:08 JST 2014]; root of context hierarchy
2014-11-22 16:13:10.140  INFO 7769 --- [           main] io.undertow.servlet                      : Initializing Spring embedded WebApplicationContext
2014-11-22 16:13:10.143  INFO 7769 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1233 ms
2014-11-22 16:13:10.247  INFO 7769 --- [           main] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'fooServlet' to [/foo]
2014-11-22 16:13:10.252  INFO 7769 --- [           main] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
2014-11-22 16:13:10.651  INFO 7769 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2014-11-22 16:13:10.671  INFO 7769 --- [           main] org.xnio                                 : XNIO version 3.3.0.Final
2014-11-22 16:13:10.696  INFO 7769 --- [           main] org.xnio.nio                             : XNIO NIO Implementation Version 3.3.0.Final
2014-11-22 16:13:10.793  INFO 7769 --- [           main] com.example.Application                  : Started Application in 2.248 seconds (JVM running for 2.698)
```

Undertow > Tomcat > Jettyな順番になっちゃった。Jettyの方が速い印象があるの意外だった。（というか普段Jettyの方が体感1秒くらい速い）きっと比較の仕方も良くないのだろう。

とにかくUndertowが使えてうれしいですね。


ちなみにRC2のUndertow対応だと依存関係が足りなくて、BeanValidationを使うと(`spring-boot-starter-web`に含まれる)起動時にこけます。以下の依存関係追加が必要。

	<dependency>
		<groupId>org.jboss.spec.javax.el</groupId>
		<artifactId>jboss-el-api_3.0_spec</artifactId>
		<version>1.0.4.Final</version>
	</dependency>

面倒くさいから次のバージョンで入れてもらえるように[Pull Request送りました](https://github.com/spring-projects/spring-boot/pull/1979)。


<a href="http://www.amazon.co.jp/%E3%81%AF%E3%81%98%E3%82%81%E3%81%A6%E3%81%AESpring-Boot%E2%80%95%E3%80%8CSpring-Framework%E3%80%8D%E3%81%A7%E7%B0%A1%E5%8D%98Java-BOOKS-%E4%BF%8A%E6%98%8E/dp/4777518655%3FSubscriptionId%3DAKIAJ7Y2FDFBWLT5HCQA%26tag%3Dikam-22%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4777518655"><img src="http://ecx.images-amazon.com/images/I/51NngrEolCL._SL160_.jpg" title="はじめてのSpring Boot―「Spring Framework」で簡単Java (I/O BOOKS)"></a>
