Switching Spring Boot 3 from Tomcat to Undertow: Step‑by‑Step Configuration and Performance Tuning
This guide explains why Tomcat may become a bottleneck under sudden high concurrency, introduces Undertow as a lightweight non‑blocking alternative, and provides detailed Maven, YAML/Properties, thread‑pool, timeout, request‑size, compression, HTTP/2, and access‑log configurations along with monitoring tips for Spring Boot 3 applications.
Optimization Background
When an application must support sudden high concurrency, Tomcat is no longer the optimal choice; Undertow offers a lightweight, high‑performance, non‑blocking I/O server developed by JBoss.
Switching Spring Boot 3 from Tomcat to Undertow
In pom.xml exclude the default Tomcat starter and add the Undertow starter:
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>Multithread Optimisation
Add thread‑pool settings in application.yml (or application.properties):
server:
undertow:
threads:
# I/O threads (recommended 1‑2× CPU cores)
io: 16
# Worker threads (recommended 8‑16× CPU cores)
worker: 256
buffer-size: 1024
direct-buffers: trueRequest Timeout Limits
server:
undertow:
no-request-timeout: 30000 # request timeout in ms
idle-timeout: 60000 # idle connection timeout in msRequest Body Size Limit
server:
undertow:
max-http-post-size: 2048 # 2 KB limit for POST bodiesResponse Compression
Enable Gzip/Deflate compression to reduce payload size and improve bandwidth usage:
server:
compression:
enabled: true
min-response-size: 1024 # trigger compression for responses ≥ 1 KB
mime-types: application/json, text/html, text/xml, text/plain, text/css, application/javascript
excluded-user-agents: IE6, IE7Enable HTTP/2 (requires SSL)
server:
http2:
enabled: trueUndertow Access Log
server:
undertow:
accesslog:
enabled: true
dir: ./logs
prefix: access_log.
suffix: .log
pattern: '%t %a "%r" %s (%D ms)'
rotate: trueMonitoring and Tuning Recommendations
Monitor thread‑pool status via JMX or Spring Actuator.
Conduct load testing with JMeter or wrk to observe thread‑pool behaviour.
Adjust JVM heap and GC parameters based on observed load.
If a database is used, align connection‑pool size with the server’s thread count.
Appendix: Undertow Configuration Properties
Spring Boot exposes many properties prefixed with server.undertow. for fine‑grained control. The following diagrams summarise the hierarchy:
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
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.
