Boost Spring Boot Performance: Switch from Tomcat to Undertow and Optimize Settings

This guide explains why Tomcat may become a bottleneck under high concurrency, shows how to replace it with the lightweight Undertow server in Spring Boot 3, and provides detailed configuration snippets for thread pools, timeouts, request size limits, compression, HTTP/2, access logging, and monitoring recommendations.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Boost Spring Boot Performance: Switch from Tomcat to Undertow and Optimize Settings

Optimization Background

When your application needs to support instantaneous high concurrency, Tomcat is no longer the optimal choice; you can switch to Undertow and optimize it.

Undertow is a lightweight, high‑performance Java web server developed by JBoss and open‑sourced. It is based on a non‑blocking I/O model, offering low resource consumption and high concurrency handling.

Switch Spring Boot 3 from Tomcat to Undertow

Add the following dependencies to pom.xml to exclude Tomcat and include Undertow:

<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>

Thread‑Pool Optimization

Add the following configuration to application.yml or application.properties:

server:
  undertow:
    # Thread pool configuration
    threads:
      # I/O threads (recommend 1‑2× CPU cores)
      io: 16
      # Worker threads (recommend 8‑16× CPU cores)
      worker: 256
    # Buffer configuration
    buffer-size: 1024
    direct-buffers: true

Request Timeout Limits

server:
  undertow:
    # Request timeout (ms)
    no-request-timeout: 30000
    # Idle connection timeout (ms)
    idle-timeout: 60000

Limit Request Body Size to 2 KB

server:
  undertow:
    max-http-post-size: 2048

Enable Response Compression

Spring Boot’s server compression reduces response size, improves transfer efficiency, and speeds up page loading.

Benefits

Reduce data transfer: compressed payloads lower network overhead.

Improve load speed: especially for front‑end pages and API responses.

Lower server load: less transmission time increases throughput.

Better user experience: faster page loads.

Recommended Configuration

server:
  compression:
    enabled: true   # enable compression
    min-response-size: 1024
    mime-types: application/json, text/html, text/xml, text/plain, text/css, application/javascript
    excluded-user-agents: IE6, IE7

Enable HTTP/2 (requires SSL)

server:
  http2:
    enabled: true

Undertow Access Log Configuration

server:
  undertow:
    accesslog:
      enabled: true
      dir: ./logs
      prefix: access_log.
      suffix: .log
      pattern: '%t %a "%r" %s (%D ms)'
      rotate: true

Monitoring and Tuning Recommendations

Monitor thread‑pool status: use JMX or Actuator.

Stress testing: run JMeter or wrk load tests.

JVM tuning: adjust heap and GC parameters based on load.

Connection‑pool tuning: ensure DB pool size matches server thread count.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaSpring BootUndertowTomcat replacement
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.