Boost Spring Boot Performance: 10 Essential Config Tweaks for High‑Load Apps

This article walks through ten practical Spring Boot configuration optimizations—including Tomcat connection pool, HikariCP, Jackson timezone handling, Logback rotation, Caffeine caching, Actuator endpoint exposure, file upload limits, async thread pools, static resource caching, and transaction timeouts—providing ready‑to‑use YAML snippets and clear explanations for each setting.

Architect
Architect
Architect
Boost Spring Boot Performance: 10 Essential Config Tweaks for High‑Load Apps

Preface

Spring Boot configuration optimization, each setting includes code and detailed explanation, making it easy for beginners to get started.

1. Tomcat connection pool configuration: the traffic controller for high concurrency

Configuration

server:
  tomcat:
    max-connections: 10000   # maximum connections (default 8192)
    threads:
      max: 800               # maximum worker threads (default 200)
      min-spare: 100         # minimum idle threads (default 10)
    accept-count: 100       # queue length (default 100)
    connection-timeout: 20000 # connection timeout in ms (default none)

Parameter explanation

max-connections: Maximum simultaneous connections Tomcat can handle; increase for high‑traffic scenarios.

threads.max: Maximum number of worker threads; set according to CPU cores (typically 2‑4× cores).

threads.min-spare: Minimum idle workers to handle sudden request spikes.

connection-timeout: Time to wait before dropping idle requests, preventing resource waste.

2. Database connection pool configuration: the receptionist for the database

Configuration

spring:
  datasource:
    hikari:
      maximum-pool-size: 50   # max connections (default 10)
      minimum-idle: 10        # min idle connections (default 10)
      connection-timeout: 30000 # ms
      idle-timeout: 600000      # ms (default 10 min)
      max-lifetime: 1800000    # ms (default 30 min)
      leak-detection-threshold: 60000 # ms (default 0, disabled)

Parameter explanation

maximum-pool-size: Maximum number of connections; adjust based on DB capacity (e.g., MySQL 20‑50).

minimum-idle: Always‑available idle connections to avoid on‑demand creation.

idle-timeout: Releases connections that stay idle too long.

leak-detection-threshold: Alerts when a connection is held >60 s, indicating possible leaks.

3. Jackson timezone serialization: solving distributed time inconsistency

Configuration

spring:
  jackson:
    time-zone: GMT+8
    date-format: yyyy-MM-dd HH:mm:ss
    serialization:
      write-dates-as-timestamps: false

Parameter explanation

time-zone: Forces Beijing time (GMT+8) regardless of server location.

date-format: Returns dates as "yyyy‑MM‑dd HH:mm:ss" instead of timestamps.

write-dates-as-timestamps: Disables timestamp mode for easier front‑end handling.

4. Log configuration: adding a log housekeeper

Configuration

logging:
  file:
    name: app.log
  logback:
    rollingpolicy:
      max-file-size: 100MB   # per file size limit
      max-history: 30        # keep 30 days
      total-size-cap: 3GB    # total log size cap

Parameter explanation

max-file-size: Starts a new file when the current one reaches 100 MB.

max-history: Automatically deletes logs older than 30 days.

total-size-cap: Ensures all log files together never exceed 3 GB.

5. Cache configuration: replacing the default cache to avoid memory explosion

Configuration

spring:
  cache:
    type: caffeine   # use Caffeine instead of ConcurrentHashMap
    caffeine:
      spec: maximumSize=10000,expireAfterWrite=600s

Parameter explanation

type: caffeine: Switches Spring Boot to Caffeine cache.

maximumSize=10000: Keeps at most 10 000 entries; excess entries are evicted.

expireAfterWrite=600s: Entries expire 10 minutes after being written.

6. Monitoring endpoint configuration: exposing only necessary information

Configuration

management:
  endpoints:
    web:
      exposure:
        include: health,info,metrics   # only expose three safe endpoints
  endpoint:
    health:
      show-details: when-authorized   # detailed health info for authorized users only

Parameter explanation

include: Exposes only health, info, and metrics endpoints.

show-details: Shows detailed health data only to authorized users, protecting sensitive info.

7. File upload size limit: breaking the 1 MB bottleneck

Configuration

spring:
  servlet:
    multipart:
      max-file-size: 100MB   # per file limit
      max-request-size: 100MB # total request limit
      file-size-threshold: 2KB # files >2KB are written to disk
      location: /tmp          # temporary storage path
      resolve-lazily: false   # do not delay request parsing

Parameter explanation

max-file-size: Allows single files up to 100 MB.

max-request-size: Allows the whole request (multiple files) up to 100 MB.

file-size-threshold: Files larger than 2 KB are stored on disk to save memory.

8. Asynchronous thread‑pool configuration: avoiding thread flood

Configuration

spring:
  task:
    execution:
      pool:
        core-size: 8               # always‑alive threads
        max-size: 16               # maximum threads
        queue-capacity: 100        # task queue size
        keep-alive: 60s            # idle thread keep‑alive time
        thread-name-prefix: async-task-
    scheduling:
      pool:
        size: 4
        thread-name-prefix: scheduling-

Parameter explanation

core-size: Number of permanent worker threads.

max-size: Upper limit of threads; extra threads are created only when needed.

queue-capacity: Holds excess tasks before new threads are spawned.

thread-name-prefix: Prefix helps identify async threads in logs.

9. Static resource caching strategy: making pages load "fly"

Configuration

spring:
  web:
    resources:
      cache:
        cachecontrol:
          max-age: 365d   # cache static resources for one year
          cache-public: true
      chain:
        strategy:
          content:
            enabled: true
            paths: /**
        cache: true
      static-locations: classpath:/static/

Parameter explanation

max-age: 365d: Browsers reuse static files for a year without re‑downloading.

content.enabled: Enables content‑based versioning; file name changes when content changes.

10. Database transaction timeout configuration: preventing long‑running locks

Configuration

@Transactional(timeout = 30, rollbackFor = Exception.class)
public void batchProcess(List<Data> dataList) {
    // split into batches to avoid long transactions
    int batchSize = 100;
    for (int i = 0; i < dataList.size(); i += batchSize) {
        List<Data> batch = dataList.subList(i, Math.min(i + batchSize, dataList.size()));
        processBatch(batch);
    }
}

Parameter explanation

timeout = 30: Transaction rolls back automatically after 30 seconds.

rollbackFor = Exception.class: Any exception triggers a rollback, ensuring data consistency.

Batch processing: Divides large data sets into 100‑record batches, shortening each transaction.

Conclusion

Spring Boot has no universal configuration template; the parameters above are common‑scenario recommendations. In real projects you must adjust them according to the specific Spring Boot version, server capacity, and business concurrency—for example, a small project may not need a Tomcat max‑connections of 10 000.

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.

ConfigurationloggingSpring BootHikariCPTomcat
Architect
Written by

Architect

Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.

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.