laitimes

Why don't big companies use Tomcat for their SpringBoot projects?

author:Not bald programmer
Why don't big companies use Tomcat for their SpringBoot projects?

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

At the same time, SpringBoot also supports Undertow containers, we can easily replace Tomcat with Undertow, and Undertow is better than Tomcat in terms of performance and memory usage, so how do we use Undertow technology? This article will explain it in detail for you.

Why don't big companies use Tomcat for their SpringBoot projects?

SpringBoot中的Tomcat容器

SpringBoot is arguably the most popular Java web framework out there. It frees developers from the heavy xml and allows developers to create a complete web service in minutes, greatly improving developer productivity. Web container technology is an essential part of a web project, because any web project needs to be run with the help of container technology.

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

Why don't big companies use Tomcat for their SpringBoot projects?

SpringBoot设置Undertow

Java programmers should be familiar with Tomcat technology, which is the most commonly used container technology for web applications. Our earliest development projects were basically deployed under Tomcat, so what container technology can we use in SpringBoot in addition to Tomcat containers?

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

  • What is Undertow? Undertow is a flexible, high-performance web server developed in Java that provides both blocking and NICO-based non-clogging mechanisms. Undertow is an open source product of Red Hat and is Wildfly's default web server. Undertow provides a basic architecture for building a web server, a project designed entirely for embedded, providing an easy-to-use builder API that is fully backwards compatible with Java EE Servlet 3.1 and low-level non-clogging processors.
  • Features of Undertow:
    • High performance In the stress test of many similar products, it performs well in high concurrency situations.
    • Servlet4.0 支持 它提供了对 Servlet4.0 的支持。
    • Web Sockets are fully supported, including JSR-356, to meet the huge number of clients in web applications.
    • Embedded It doesn't require containers, and you can quickly set up a web server through an API.
    • Flexibility Configuring and processing requests with a chained Handler minimizes the need to load modules on demand, eliminating the need to load redundant functions.
    • Lightweight It is an inline web server, consisting of two core JAR packages

SrpingBoot is already fully integrated with the Undertow technology, we just need to introduce the dependencies of Undertow as shown below.

  • Remove the dependency on Tomcat
<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>           
  • Add Undertow dependencies
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>           

Once configured, we launch the application and find that the container has been replaced with Undertow.

Why don't big companies use Tomcat for their SpringBoot projects?

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

Why don't big companies use Tomcat for their SpringBoot projects?

Comparison of Tomcat vs Undertow

Tomcat is a lightweight servlet container under the Apache Foundation that supports both servlets and JSPs. Tomcat has features unique to web servers, including the Tomcat Management and Control Platform, the Security Bureau Administration, and the Tomcat Valve. Tomcat itself contains an HTTP server, so it can also be thought of as a separate web server.

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

Why don't big companies use Tomcat for their SpringBoot projects?

Undertow is a flexible, high-performance web server that supports both blocking and non-blocking IOs. Since Undertow is developed in Java, it can be embedded directly into Java projects. At the same time, Undertow fully supports servlets and Web sockets, which is very good in high-concurrency situations.

Why don't big companies use Tomcat for their SpringBoot projects?

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

Comparison of QPS test results:

  • Tomcat
  • Undertow

Memory Usage Comparison:

  • Tomcat
  • Undertow

Through testing, it is found that Tomcat is relatively weak in high-concurrency systems. Simulating an equal number of requests with the same machine configuration, Undertow is optimal in terms of performance and memory usage. In addition, the new version of Undertow uses persistent connections by default, which will further improve its concurrent throughput capabilities. Therefore, if it is a high-concurrency business system, Undertow is the best choice.

Why don't big companies use Tomcat for their SpringBoot projects?

At last

In SpingBoot we can use Tomcat as an HTTP service or Undertow instead. Undertow's performance is better than Tomcat in high-concurrency service scenarios. So, if our system is a high concurrency request, you might as well use Undertow and you will find that your system performance will be greatly improved.