For more selected articles, please click:Java notes.md
Read by little hub:
The performance and memory usage of undertow are better than tomcat, which is why undertow is popular! You can also try to switch in the springboot project and its simple!
- Author: Amada
At the same time, springboot also supports the undertow container. We can easily replace Tomcat with undertow, and the performance and memory usage of undertow are better than Tomcat. How can we use the undertow technology? This article will explain for you in detail.
Tomcat container in springboot
Springboot is the most popular java web framework. It saves developers from the heavy XML, allows developers to create a complete web service in a few minutes, and greatly improves the efficiency of developers. Web container technology is an indispensable part of Web project, because any web project must run with the help of container technology.
In the framework of springboot, we use Tomcat the most, which is the default container technology of springboot and is embedded Tomcat.
Springboot setting 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 are basically deployed under Tomcat. In addition to Tomcat container, what container technology can we use in springboot?
Yes, it’s the undertow container technology in the title. Srpingboot has fully inherited the undertow technology. We only need to introduce the dependency of undertow, as shown in the figure below.
After configuration, we start the application and find that the container has been replaced with undertow.
So why do we need to replace Tomcat with undertow technology?
Comparison of Tomcat and undertow
Tomcat is a lightweight servlet container under Apache foundation, which supports servlet and JSP. Tomcat has the unique functions of web server, including Tomcat management and control platform, Security Bureau Management and Tomcat valve. Tomcat itself contains 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 is very popular among developers（http://220.127.116.11:8888/home?id=62)）
Undertow is an open source product of red hat company. It is fully developed in Java language. It is a flexible high-performance web server, supporting blocking IO and non blocking io. Because subtow is developed in Java language, it can be directly embedded into Java projects. At the same time, subtow fully supports servlet and web socket, and performs very well in the case of high concurrency.
We test Tomcat and undertow under the same machine configuration, and the test results are as follows:
Comparison of QPS test results:
Memory usage comparison:
The test shows that Tomcat is relatively weak in high concurrency system. Under the same machine configuration, simulating the same number of requests, undertow is the best 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.
In spingboot, we can use Tomcat as HTTP service or undertow instead. Undertow is better than Tomcat in high concurrency scenarios. Therefore, if our system is highly concurrent, you might as well use undertow, and you will find that your system performance will be greatly improved.