Why do big companies prohibit the use of Tomcat in Spring Boot projects?

Source: toutiao.com/a6775476659416990212

foreword

In the SpringBoot framework, we use Tomcat the most, which is the default container technology of SpringBoot, and it is an embedded Tomcat.

At the same time, SpringBoot also supports Undertow containers. We can easily replace Tomcat with Undertow, and Undertow's performance and memory usage are better than Tomcat. So how do we use Undertow technology?

This article will explain it in detail.

Tomcat container in SpringBoot

SpringBoot can be said to be the hottest Java Web framework at present.

It saves developers from the heavy xml, allows developers to create a complete web service in a few minutes, and greatly improves the developer's work efficiency.

Web container technology is an essential part of Web projects, because any Web project must rely on container technology to run.

In the SpringBoot framework, we use Tomcat the most, which is the default container technology of SpringBoot, and it is an embedded Tomcat.

SpringBoot sets Undertow

Java programmers should be very familiar with Tomcat technology, which is the most commonly used container technology for Web applications.

Our earliest development projects were basically deployed and run under Tomcat. In addition to the Tomcat container, what container technology can we use in SpringBoot?

That's right, it is the Undertow container technology in the title.

SrpingBoot has fully inherited the Undertow technology, we only need to introduce the dependencies of Undertow, as shown in the figure below.

I won’t introduce the basics of Spring Boot. It is recommended to watch this practical project:

https://github.com/javastacks/spring-boot-best-practice

After configuring, we started the application and found that the container has been replaced with Undertow.

Then why do we need to replace Tomcat with Undertow technology?

Comparison of the advantages and disadvantages of Tomcat and Undertow

Tomcat is a lightweight Servlet container under the Apache foundation, supporting Servlet and JSP.

Tomcat has the unique functions of Web server, including Tomcat management and control platform, security bureau management and Tomcat valve, etc.

Tomcat itself includes an HTTP server, so it can also be regarded as a separate Web server.

However, Tomcat and Apache HTTP server are not the same thing. Apache HTTP server is an HTTP Web server implemented in C language. Tomcat is completely free and loved by developers.

Undertow is an open source product of Red Hat. It is developed entirely in Java language. It is a flexible high-performance web server that supports blocking IO and non-blocking IO.

Since Undertow is developed in Java language, it can be directly embedded in Java projects. At the same time, Undertow fully supports Servlet and Web Socket, and performs very well in high concurrency situations.

We stress tested Tomcat and Undertow under the same machine configuration, and the test results obtained are as follows:

Comparison of QPS test results:

Tomcat

Undertow

Memory usage comparison:

Tomcat

Undertow

Through testing, it is found that in high-concurrency systems, Tomcat is relatively weak. Under the same machine configuration, simulating an equal number of requests, Undertow is optimal in terms of performance and memory usage.

And the new version of Undertow uses persistent connections by default, which will further improve its concurrent throughput. Therefore, if it is a high-concurrency business system, Undertow is the best choice.

at last

In SpingBoot, we can use Tomcat as the Http service, or use Undertow instead.

Undertow has better performance than Tomcat in high-concurrency business scenarios. Therefore, if our system has high concurrent requests, you might as well use Undertow, and you will find that your system performance will be greatly improved.

Recent hot article recommendation:

1. 1,000+ Java interview questions and answers (2022 latest version)

2. Brilliant! Java coroutines are coming. . .

3. Spring Boot 2.x tutorial, too comprehensive!

4. Don't fill the screen with explosions and explosions, try the decorator mode, this is the elegant way! !

5. The latest release of "Java Development Manual (Songshan Edition)", download quickly!

Feel good, don't forget to like + forward!

Guess you like

Origin blog.csdn.net/youanyyou/article/details/131833100