First, undertow

1. Undertow

Undertow is a flexible, high-performance Web server that provides NIO’s blocking/non-blocking API and is the default Web container for Wildfly. In the javaweb container world, tomcat and jetty are well known, and undertow is now moving into the public’s mind as a companion to tomcat and beating tomcat in terms of performance. Undertow is now one of the three containers that springboot integrates with by default.

2. Undertow features:

Undertow performs better than Tomcat in high-concurrency service scenarios

1, high performance, in the pressure test comparison of many similar products, excellent performance under high concurrency.

Servlet4.0 support, which provides support for Servlet4.0.

3. Web Socket is fully supported, including JSR-356, to meet the huge number of clients for Web applications.

4, embedded, it does not need a container, only through API can quickly build a Web server.

5, flexibility, by the chain Handler configuration and processing requests, can minimize the load on demand module, no need to load redundant functions.

6. Lightweight, it is an embedded Web server consisting of two core JAR packages.

3. Springboot integrated Web server

2.2.13.RELEASE Springboot Version The following three Servlet container versions are supported by default

2.2.13.RELEASE Springboot version (provided by official website)

The web server version
Undertow 2.0.33. The Final
tomcat 9.0.41
jetty 4.1.17

Second, experimental verification

Materials prepared for the experiment are as follows:

1. Springboot version

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.2.2. RELEASE</version>
</parent>
Copy the code

2. Test class controller

@RequestMapping("/reflect")
@ResponseBody
public void reflect() {
    Object object = springReflectionUtil.springInvokeMethod("reflectService"."handleUser");
    if (object instanceofUser) { User invoke = (User)object; }}Copy the code

3, SpringBoot is embedded with Tomcat by default

Introduce the following dependencies in the POM file

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
Copy the code

4. Project integration of Undertow

Introduce the following dependencies in the POM file

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> </dependency> <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>Copy the code

5. Project integration of Jetty

Introduce the following dependencies in the POM file

<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>Copy the code

6. JVM configuration

-server
-Xms4096m
-Xmx4096m
-XX:+UseG1GC
Copy the code

7. Pressure test with Jmeter

Tomcat, Jetty, and Undertow simulate 100,000 requests and check their throughput data respectively. Scenario 1:100 threads cycle the test interface for 1000 times and simulate 100,000 requests. Scenario 2:1000 threads cycle the test interface for 100 times and simulate 100,000 requests

8. Experimental results

Tomcat 100 threads loop through throughput data 1000 times

1000 threads loop the throughput data 100 times

Jetty 100 threads loop through throughput data 1000 times

1000 threads loop the throughput data 100 times

Undertow 100 threads loop 1000 times through throughput data

1000 threads loop the throughput data 100 times

The results of the pressure test are as follows

100 threads loop 1000 times (throughput/SEC)

The server For the first time, The second time The third time The average
Tomcat 1119.7 1497.5 1490.5 1369.2
jetty 1363.7 1429.3 1390.5 1394.5
undertow 1607.9 1467.3 1545.6 1540.3

1000 threads loop 100 times (throughput/SEC)

The server For the first time, The second time The third time The average
Tomcat 1212.2 1088.4 1107.5 1136.0
jetty 1225.9 1222.6 1186.3 1211.6
undertow 1383.7 1468.1 1434.2 1428.7

Third, experimental conclusions

The default configuration is used for 1000 cycles of 100 threads. The average throughput of Tomcat without configuration parameters is 1369.2 per second, the average throughput of Jetty is 1394.5, and the average throughput of Undertow is 1540.3 per second

1000 threads loop 100 times, using the default configuration, with no configuration parameters

The average tomcat throughput is 1136.0 per second, jetty throughput is 1211.6, and Undertow throughput is 1428.7 per second

You can see that the default configuration is

Undertow’s throughput is better than jetty’s and Tomcat’s

undertow>jetty>tomcat

One last word

Thank you for reading. Your positive feedback is the motivation for my continuous creation. I am looking forward to your attention!