Why Switch to Undertow in Spring Boot? Performance and Memory Gains Over Tomcat
This article explains how to replace Spring Boot's default embedded Tomcat with Undertow, compares their architectures, presents benchmark results showing Undertow's superior throughput and lower memory usage, and concludes that Undertow is the better choice for high‑concurrency Java web applications.
Introduction
Spring Boot ships with an embedded Tomcat server as its default servlet container. Undertow is a high‑performance, non‑blocking Java web server that can be used as an alternative, often providing better throughput and lower memory consumption.
Configuring Undertow in Spring Boot
Replace Tomcat by adding the Undertow starter dependency to the project and rebuilding the application. After the rebuild, Spring Boot starts with Undertow as the HTTP server.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>For Gradle projects:
implementation 'org.springframework.boot:spring-boot-starter-undertow'Why Use Undertow
Fully written in Java, allowing direct embedding in Java applications.
Supports both blocking and non‑blocking I/O.
Provides native support for Servlet, JSP, and WebSocket.
Consumes less heap memory under load.
Higher queries‑per‑second (QPS) performance in high‑concurrency scenarios.
Tomcat vs. Undertow
Tomcat : Apache‑sponsored lightweight servlet container, includes an HTTP server, extensive management tools, but uses a thread‑per‑request model.
Undertow : Red Hat’s open‑source server, flexible architecture, uses an event‑driven, non‑blocking model, and defaults to persistent connections in recent versions.
Benchmark Results
Performance tests on identical hardware show that Undertow delivers higher QPS and lower memory usage than Tomcat under the same load.
QPS – Tomcat
QPS – Undertow
Memory Usage – Tomcat
Memory Usage – Undertow
Conclusion
For high‑concurrency business systems, Undertow provides superior throughput and lower memory consumption compared with Tomcat, making it the preferred embedded server for Spring Boot applications.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
