Cloud Native 10 min read

Spring Cloud Performance Tuning: Optimizing Feign, Hystrix, Ribbon, Zuul, and Servlet Container

This guide explains how to improve Spring Cloud's low default performance by configuring and tuning components such as the servlet container (switching to Undertow), Feign, Hystrix, Ribbon, and Zuul, providing detailed code snippets and parameter recommendations for high‑concurrency scenarios.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Spring Cloud Performance Tuning: Optimizing Feign, Hystrix, Ribbon, Zuul, and Servlet Container

Spring Cloud Performance Issues

Spring Cloud's default configuration yields low performance, often failing to reach 50 QPS in JMeter tests; achieving high concurrency requires extensive configuration optimizations.

Feign configuration optimization

Hystrix configuration optimization

Ribbon optimization

Servlet container optimization

Zuul configuration optimization

Application Service Component Tuning

Servlet Container Optimization

By default, Spring Boot uses Tomcat as the embedded servlet container. Switching to Undertow, a high‑performance NIO‑based server, can improve performance.

To replace Tomcat with Undertow, modify the pom.xml as follows:

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

Then add the Undertow starter:

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

Configure Undertow properties:

server:
  undertow:
    io-threads: 16
    worker-threads: 256
    buffer-size: 1024
    buffers-per-region: 1024
    direct-buffers: true

Explanation of key properties such as server.undertow.io-threads , server.undertow.worker-threads , server.undertow.buffer-size , server.undertow.buffers-per-region , and server.undertow.direct-buffers is provided.

Feign Configuration Optimization

Enable Hystrix for Feign:

feign.hystrix.enabled=true

Enable request and response compression:

feign:
  compression:
    request:
      enabled: true
      mime-types: text/xml,application/xml,application/json
    response:
      enabled: true

Switch the HTTP client to Apache HttpClient or OkHttp for connection pooling:

feign:
  httpclient:
    enabled: true
    max-connections: 1000
    max-connections-per-route: 200
feign:
  okhttp:
    enabled: true
  httpclient:
    max-connections: 1000
    max-connections-per-route: 200

Adjust max-connections and max-connections-per-route according to workload.

Gateway Component Tuning

Zuul Configuration Optimization

Increase the default semaphore limit (default 100) to handle more concurrent requests:

zuul:
  semaphore:
    max-semaphores: 5000

For thread isolation, enlarge the Hystrix thread pool:

zuul:
  ribbonIsolationStrategy: THREAD
hystrix:
  threadpool:
    default:
      coreSize: 100
      maximumSize: 400
      allowMaximumSizeToDivergeFromCoreSize: true
      maxQueueSize: -1

Key Hystrix properties such as hystrix.threadpool.default.allowMaximumSizeToDivergeFromCoreSize and hystrix.threadpool.default.maxQueueSize are explained.

Hystrix Configuration Optimization

Set core thread pool size and increase timeout to avoid early failures:

hystrix:
  threadpool:
    default:
      coreSize: 500
  command:
    default:
      circuitBreaker:
        requestVolumeThreshold: 1000
      fallback:
        enabled: true
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 100000

Additional properties such as hystrix.command.default.fallback.enabled , hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds , and circuit‑breaker thresholds are described.

Ribbon Optimization

Enable eager loading of Ribbon clients to avoid first‑call latency:

ribbon:
  eager-load:
    enabled: true
    clients: service-1,service-2,service-n

Explain the effect of ribbon.eager-load.enabled and ribbon.eager-load.clients . Also discuss Zuul's eager‑load behavior and how to disable default route mapping using zuul.ignored-services=* .

Performance TuningfeignSpring CloudUndertowHystrixribbonZuul
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

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