Why does the company prohibit the SpringBoot project from using Tomcat?

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.
insert image description here
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.
insert image description here
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.
insert image description here
We stress tested Tomcat and Undertow under the same machine configuration, and the test results obtained are as follows:

Comparison of QPS test results:
insert image description here
Comparison of memory usage:
insert image description here
Through testing, it is found that Tomcat is relatively weak in high-concurrency systems. 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.

expand

Not only that, but there are many web-side servers on the market, such as nginx, Weblogic, WebSphere and so on. . . . Everyone can understand

Guess you like

Origin blog.csdn.net/aq_money/article/details/130304942