日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Tomcat vs. Jetty vs. Undertow: Comparison of Spring Boot Embedded Servlet Containers

發布時間:2025/4/5 javascript 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Tomcat vs. Jetty vs. Undertow: Comparison of Spring Boot Embedded Servlet Containers 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原文地址:https://examples.javacodegeeks.com/enterprise-java/spring/tomcat-vs-jetty-vs-undertow-comparison-of-spring-boot-embedded-servlet-containers/

With the rise in popularity of micro services we have seen a similar rise in popularity of applications with embedded servlet containers. Spring boot is a Java based framework that supports application services. It runs as a standalone jar with an embedded servlet container or as a WAR file inside a container.

In this example, we will focus on the standalone jar with embedded servlet containers. The framework supports three different types of embedded servlet containers: Tomcat (default), Jetty and Undertow. We will compare the three and look at differences in properties, settings, performance and memory. Keep in mind that this example is analyzing the default configuration. There are many ways to optimize the performance or memory usage including to customize the auto configuration and component scanning.

We used Eclipse Neon, Java 8, Maven 3.3.9, Spring 1.4.3, Tomcat 8.5.6, Jetty 9.3.14 and Undertow 1.3.24.

Table Of Contents

1. Setup Spring Boot Application2. Tomcat3. Jetty4. Undertow5. Performance and Load
5.1. Measure Performance5.2. Measure Memory
6. Comparison7. Conclusion8. Download the Source Code

1. Setup Spring Boot Application

We will use Maven to setup a new project in Eclipse with the appropriate dependencies. We will use the starter parent for this example but the dependencies in a production application will likely be altered to streamline, optimize or customize.

1.1 Setup Spring Boot Dependencies

The default embedded servlet container is Tomcat. This version of Spring Web 1.4.3 brings in Tomcat version 8.5.6.

pom.xml

01<parent>
02???<groupId>org.springframework.boot</groupId>
03???<artifactId>spring-boot-starter-parent</artifactId>
04???<version>1.4.3.RELEASE</version>
05</parent>
06?
07<dependencies>
08???<!-- TOMCAT -->
09???<dependency>
10??????<groupId>org.springframework.boot</groupId>
11??????<artifactId>spring-boot-starter-web</artifactId>
12???</dependency>
13</dependencies>

1.2 Setup Spring Boot Main Application and Controllers

To setup the Spring Boot application you include the?@SpringBootApplication?annotation in your Main class. The?@SpringBootApplication?annotation brings in?@SpringBootConfiguration,?@EnableAutoConfiguration?and?@ComponentScanannotations.

Application.java

1@SpringBootApplication
2@ConfigurationProperties
3public?class?Application {
4public?static?void?main(String[] args) {
5???SpringApplication.run(Application.class, args);
6}

You may choose to eliminate this annotation and add the?@SpringBootConfiguration?alone or to another class that allows you to customize the configuration. The?@ComponentScan?will scan your application for items like the?@Controller?you will need to setup a RESTful service. The following controller will return a simple “Hello World” string from a HTTP GET request. We have also included in the bundled example another endpoint mapping that returns a complex object type.

SampleController.java

01@Controller
02public?class?SampleController {
03?
04@Autowired
05private?ResourceLoader resourceLoader;
06?
07@RequestMapping("/")
08@ResponseBody
09public?String home() {
10???return?"Hello World!";
11}

1.3 Key Configuration Parameters

The default properties for all the embedded servlet containers are the same. Some of the most important properties to consider are the properties for configuring startup information like ports and application name, TSL, access logs, compression and many more.

For example, to configure SSL add the following to key value pairs to the application.properties.

application.properties

1server.port=8443
2server.ssl.key-store=classpath:keystore.jks
3server.ssl.key-store-password=secret
4server.ssl.key-password=another-secret

1.4 How to Find Additional Parameters

To explore the parameters for Spring boot applications you can add the Spring actuator dependency and the?@ConfigurationProperties?annotation to your Main class. You then visit the?/configprops?endpoint on your application to get a list of the available properties.

Application.java

1@SpringBootApplication
2@ConfigurationProperties
3public?class?Application {

pom.xml

1<dependency>
2???<groupId>org.springframework.boot</groupId>
3???<artifactId>spring-boot-starter-actuator</artifactId>
4</dependency>
1http://localhost:8080/jcg/service/configprops

1.5 Change version of Embedded Servlet Containers

The embedded servlet container versions are defined in the following parent dependency from the pom. You can change the version of the embedded servlet container by explicitly including the dependency and identifying a new version in the pom. We will show you how in the examples below.

pom.xml

1<dependency>
2???<groupId>org.springframework.boot</groupId>
3???<artifactId>spring-boot-dependencies</artifactId>
4???<version>1.3.7.RELEASE</version>
5</dependency>

2. Tomcat

As Tomcat is the default embedded servlet container there is nothing you need to do to the default implementation to use Tomcat. You can change the version of Tomcat you are using or change properties in the?pom.xml?or?application.properties?files.

2.2 Change Version of Tomcat

pom.xml

01<properties><tomcat.version>8.5.6</tomcat.version></properties>
02?
03<dependency>
04???<groupId>org.apache.tomcat.embed</groupId>
05???<artifactId>tomcat-embed-core</artifactId>
06???<version>${tomcat.version}</version>
07</dependency>
08<dependency>
09???<groupId>org.apache.tomcat.embed</groupId>
10???<artifactId>tomcat-embed-el</artifactId>
11???<version>${tomcat.version}</version>
12</dependency>
13<dependency>
14???<groupId>org.apache.tomcat.embed</groupId>
15???<artifactId>tomcat-embed-websocket</artifactId>
16???<version>${tomcat.version}</version>
17</dependency>

3. Jetty

To change the embedded servlet container to Jetty you need to edit the pom file to remove the Tomcat dependency and add Jetty.

3.1 Change to Jetty (version 9.3.14)

pom.xml

01<dependency>
02???<groupId>org.springframework.boot</groupId>
03???<artifactId>spring-boot-starter-web</artifactId>
04???<exclusions>
05??????<exclusion>
06?????????<groupId>org.springframework.boot</groupId>
07?????????<artifactId>spring-boot-starter-tomcat</artifactId>
08??????</exclusion>
09???</exclusions>
10</dependency>
11<dependency>
12???<groupId>org.springframework.boot</groupId>
13???<artifactId>spring-boot-starter-jetty</artifactId>
14</dependency>

4. Undertow

To change the embedded servlet container to Undertow you need to edit the pom file to remove the Tomcat dependency and add Undertow.

4.1 Change to Undertow (version 1.3.24 final)

Notice the undertow version included in the spring boot starter is incorrect, referring to 1.3.25. You’ll need to change it to 1.3.24.Final for this to work at the time of this article.

pom.xml

01<dependency>
02???<groupId>org.springframework.boot</groupId>
03???<artifactId>spring-boot-starter-web</artifactId>
04???<exclusions>
05??????<exclusion>
06?????????<groupId>org.springframework.boot</groupId>
07?????????<artifactId>spring-boot-starter-tomcat</artifactId>
08??????</exclusion>
09???</exclusions>
10</dependency>
11<dependency>
12???<groupId>org.springframework.boot</groupId>
13???<artifactId>spring-boot-starter-undertow</artifactId>
14</dependency>
15<dependency>
16???<groupId>io.undertow</groupId>
17???<artifactId>undertow-core</artifactId>
18???<version>1.3.24.Final</version>
19</dependency>
20<dependency>
21???<groupId>io.undertow</groupId>
22???<artifactId>undertow-servlet</artifactId>
23???<version>1.3.24.Final</version>
24</dependency>

5. Performance and Load

In this example, we will analyze both the peformance of HTTP requests and the memory footprint at startup of all three embedded servlet containers. We used JMeter to measure performance by simulating load and JVisualVM to look at the memory footprint.

5.1 Measure Performance

In this example, we will analyze both the peformance of simple RESTFul GET requests that return a string and more complex GET requests that return complex JSON objects. JMeter is the tool used to measure the performance of the the three different types of containers. The key to setting up this test was establishing thread groups with the appropriate load, a counter to dynamically update the input to the API and report viewers to display or aggregate the results. For the simple string examples, we used a thread group with 1000 threads that would loop 3 times through the sequence. It also used a ramp up time of 10 seconds. For the complex object examples, we used the same parameters but did not loop.

JMeter Tomcat Thread Group

?

JMeter Tomcat Summary Report

5.1.1 Tomcat

5.1.1.1 Simple String
Label# SamplesAverageMinMaxStd. Dev.Error %ThroughputReceived KB/secSent KB/secAvg. Bytes
Startup30007154935.783743610293.858360355.9593557255.67238466195
Others300010451.3596616820287.880241854.8209444954.53981144195
Others300010241.1550322750292.112950355.6269778555.3417113195
5.1.1.2 Complex Object with Dynamic Data
Label# SamplesAverageMinMaxStd. Dev.Error %ThroughputReceived KB/secSent KB/secAvg. Bytes
Startup100011431601322.8671905097.68486861202.333599919.937634322121
Others100032171.328216473097.88566954202.749516719.97861812121
Others100021161.110529603098.52216749204.067887920.108528332121
Others100021211.344498419098.53187506204.087995120.110509662121

5.1.2 Jetty

5.1.2.1 Simple Object
Label# SamplesAverageMinMaxStd. Dev.Error %ThroughputReceived KB/secSent KB/secAvg. Bytes
Startup30007056140.137050650291.516859456.082833355.22878197
Others300010211.0589250310293.599530256.4835033855.6233485197
Others300010210.9260343170294.348508656.6275939555.7652448197
5.1.2.2 Complex Object with Dynamic Data
Label# SamplesAverageMinMaxStd. Dev.Error %ThroughputReceived KB/secSent KB/secAvg. Bytes
Startup100011031397278.7961107098.13542689203.362671719.933758592122
Others100032201.500210319098.48335631204.083673920.004431752122
Others100032452.729377218098.29942003203.702509119.967069692122

5.1.3 Undertow

5.1.3.1 Simple Object
Label# SamplesAverageMinMaxStd. Dev.Error %ThroughputReceived KB/secSent KB/secAvg. Bytes
Startup30006045131.61887020295.683027863.8144034656.01807363221
Others300010221.2554478620292.740046863.1792483955.46051669221
Others300010181.5594779750294.377391863.5326206955.77071681221
5.1.3.2 Complex Object with Dynamic Data
Label# SamplesAverageMinMaxStd. Dev.Error %ThroughputReceived KB/secSent KB/secAvg. Bytes
Startup10007031114197.1333241097.059109203.396936119.620442012145.893
Startup1000423852132.6443576098.02960494205.632413520.007995542148
Others100032191.293570253098.55129595206.630500420.018231992147
Others100022271.659250132098.74592673207.038578820.057766372147
Others100021171.260904041098.28975821206.082139519.965107142147

?

5.2 Measure Memory

To measure the memory of each embedded servlet container we looked at the memory usage on startup. JVisualVM is a tool provided with the Java Development Kit for visualizing the memory and footprint of java applications. We used this tool to show the initial startup impact of each of the three embedded servlet containers. The heap size and thread counts are key in analyzing this initial footprint. The ten threads that are common to all three containers include: JMX server connection timeout, RMI Scheduler, RMI TCP Connection (2), RMI TCP Accept, Attach Listener, DestroyJavaVM, Signal Dispatcher, Finalizer and Reference Handler.

JVisualVM Report

5.2.2 Tomcat

Heap Size: 697,827,328 B
Used: 124,260,976 B
Max: 2,147,483,648 B

Threads: 17 Live, 22 Started

5.2.3 Jetty

Heap Size: 628,621,312 B
Used: 311,476,776 B
Max: 2,147,483,648 B

Threads: 19 Live, 22 Started

5.2.4 Undertow

Heap Size: 630,718,464 B
Used: 114,599,536 B
Max: 2,147,483,648 B

Threads: 17 Live, 20 Started

6. Compare

6.1 Performance

While all three of the embedded servlet containers had similar performance under the parameters used in this example, Undertow seems to have the best performance with Tomcat and Jetty close behind. The memory footprint of Jetty on startup was the largest using 311 MB. Tomcat and Undertow had similarly low initial footprints around 120 MB with Undertow coming in the lowest at 114 MB. The key difference in the response headers is that Undertow includes HTTP Persistent connections by default. This header will be used in clients that support persistent connections to optimize performance by reusing connection details.

6.1.1 Tomcat Response Headers

1Content-Type →application/json;charset=UTF-8
2Date →Mon, 09 Jan 2017 02:23:26 GMT
3Transfer-Encoding →chunked
4X-Application-Context →JcgSpringBootContainers:# Application index.

6.1.2 Jetty Response Headers

1Content-Type →application/json;charset=UTF-8
2Date →Mon, 09 Jan 2017 02:29:21 GMT
3Transfer-Encoding →chunked
4X-Application-Context →JcgSpringBootContainers:# Application index.

6.1.3 Undertow Response Headers

1Connection →keep-alive
2Content-Type →application/json;charset=UTF-8
3Date →Mon, 09 Jan 2017 02:20:25 GMT
4Transfer-Encoding →chunked
5X-Application-Context →JcgSpringBootContainers:# Application index.

7. Conclusion

The numbers indicate that Undertow is the best in performance and memory usage. It is encouraging to see that Undertow is embracing the latest capabilities and defaulting to persistent connections. The numbers do not indicate a dramatic difference in performance based on the load used in this example but I would imagine that they would scale and that if performance is the most important factor Undertow is the right match for your application. It is also reasonable to think that an organization may favor an embedded servlet container because of familiarity with it’s capabilities. Many times the defaults settings will have to change because of application requirements that include performance, memory usage and functionality.

8. Download the Source Code

Here we compared three types of embedded servlet containers you can include in a Spring Boot Application.

Download
You can download the Eclipse project here:?JcgSpringBootContainers

轉載于:https://www.cnblogs.com/davidwang456/p/6742711.html

總結

以上是生活随笔為你收集整理的Tomcat vs. Jetty vs. Undertow: Comparison of Spring Boot Embedded Servlet Containers的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久精品资源 | 四虎影视精品 | 天天射美女 | 第一色影院 | 韩国视频一区二区三区 | 在线视频导航 | 在线观看日本中文字幕 | 四季av一区二区三区免费观看 | 岛国二区三区 | 冲田杏梨 在线 | 欧美在线高清 | 欧美一区高清 | 午夜不卡av免费 | 丁香激情五月 | 久久久久久久女国产乱让韩 | 三级网站免费看 | 国产第一色 | 北条麻妃99精品青青久久 | 香蕉影院在线 | 亚洲国产日韩精品 | 精品久久久久久无码中文野结衣 | 亚洲美女av网站 | 日日爽 | 亚洲特黄毛片 | 亚洲一级网 | 国产福利久久久 | 娇小的粉嫩xxx极品 国产精品人人爽人人爽 | 九九九久久久 | av在线播放网站 | 理想之城连续剧40集免费播放 | 亚洲综合一 | 男女洗澡互摸私密部位视频 | 二区在线播放 | 久久7777 | 鲁大师私人影院在线观看 | 午夜精品久久久久久久久久久 | 欧美综合网 | 免费国产在线视频 | 美女网站一区 | 性欧美17一18内谢 | 国产极品一区二区 | 日本五十路女优 | 国产成人超碰人人澡人人澡 | 干日本少妇首页 | 中文字幕av亚洲精品一部二部 | 欧美一区二区免费在线观看 | 精品人妻无码专区视频 | 国产精品50页| 日韩欧美手机在线 | 台湾佬中文字幕 | 高清中文字幕在线a片 | 蜜桃av噜噜一区二区三区麻豆 | 国产精品一二三 | 黄色复仇草 | 91国产视频在线观看 | 伊人伊人网 | 日本在线三级 | 日本伦理一区二区 | 成人黄色在线免费观看 | 国产制服av | 男女国产精品 | 黄色靠逼视频 | 亚洲精品鲁一鲁一区二区三区 | 中文字幕av专区dvd | 精品在线视频免费观看 | 亚洲天堂系列 | 在线观看免费黄色小视频 | 一区二区三区激情视频 | 欧美视频在线一区 | 水蜜桃av在线| 日本爽妇网 | 久久精品99国产国产精 | 一级特黄av | wwwav在线播放 | 伦伦影院午夜理论片 | 免费啪啪网 | 精品成人av一区二区在线播放 | 青草精品| 伊人久久视频 | 亚洲视频1区| 国产51页 | 日韩午夜在线 | 99国产精品久久久久久久久久久 | 91网站观看 | 免费观看黄色av | 日本少妇色 | 九九热播视频 | 桃色综合网 | 色撸撸在线 | 日韩一区二区三区四区五区 | 欧美一级二级三级视频 | 天天人人精品 | 97爱视频 | 久久国产福利一区 | 99视频在线看 | 亚洲a视频在线观看 | 在线免费观看成年人视频 | 伊人影视久久 | 午夜99 |