官方文档

pom依赖:

tomcat:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.3.RELEASE</version>
</parent>


<dependencies>
    <!-- TOMCAT -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>



jetty:

<dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-web</artifactId>
       <exclusions>
          <exclusion>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-tomcat</artifactId>
          </exclusion>
       </exclusions>
</dependency>
<dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

Undertow:

<dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-web</artifactId>
       <exclusions>
          <exclusion>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-tomcat</artifactId>
          </exclusion>
       </exclusions>
</dependency>
<dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
       <groupId>io.undertow</groupId>
       <artifactId>undertow-core</artifactId>
       <version>1.3.24.Final</version>
</dependency>
<dependency>
       <groupId>io.undertow</groupId>
       <artifactId>undertow-servlet</artifactId>
       <version>1.3.24.Final</version>
</dependency>

Undertow 什么鬼?
Undertow 是 RedHat(红帽公司)的开源产品,采用 Java 开发,是一款灵活、高性能的 Web 服务器,提供了基于 NIO 的阻塞/非阻塞 APIs,也是 Wildfly的默认 Web 容器
Undertow 它是一个基于组合的体系结构,可以通过组合一系列小型处理器来构建一个 Web 服务器。这就让我们可以灵活的在 Java EE servlet 4.0 容器和底层非阻塞处理器或者其他更多之间进行选择。
Undertow 被设计成完全可嵌入式的,所以也叫嵌入式容器,具有易于使用的流畅构建 API,另外,Undertow 的生命周期也完全由所嵌入的应用程序所控制。
这也是为什么 Spring Boot 可以直接嵌入 Undertow 的原因,Undertow 它就是为了嵌入而发烧的

Undertow 有啥特性?
1)HTTP/2 Support
Undertow 支持 HTTP/2 开箱即用,不需要重写引导类路径。
2)支持 HTTP 升级
支持 HTTP 升级,允许多个协议通过 HTTP 端口上进行复用。
3)支持 Web Socket
Undertow 提供对 Web 套接字的全面支持,包括对 JSR-356 的支持。
4)支持 Servlet 4.0
Undertow 提供了对 Servlet 4.0 的支持,包括对嵌入式 Servlet 的支持,还可以混合部署 Servlet 和原生 Undertow 非阻塞处理程序。
5)可嵌入式
Undertow 可以嵌入到应用程序中,也可以通过几行代码独立运行。

6)高灵活性
一个 Undertow 服务器是通过链式处理器来配置的,可以根据需要添加功能,因此可以避免添加没有必要的功能。
Undertow 性能如何?

Tomcat vs. Jetty vs. Undertow 三者的性能比较:

从测试结果看,这三个 Servlet 容器都具有不错的性能,但 Undertow 性能更好,Tomcat 和 Jetty 紧随其后。

Jetty 在启动时的内存占用最大,为:311 MB, Tomcat 和 Undertow 的初始内存占用都很低,大约为:120 MB,而 Undertow 的初始内存占用最低,为:114 MB。

最后,关键的区别在于,Undertow 响应头参数默认包含 HTTP 持久连接信息,这个头参数在支持持久连接的客户端时,可以通过重用连接来优化性能。

 

分类: tomcat

0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据