You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何更换Spring Boot内置Web服务器及性能评估相关问题

Spring Boot Web服务器相关问题解答

一、如何更换Spring Boot默认Web服务器

Spring Boot默认使用Tomcat,更换为Jetty或Undertow的步骤如下:

1. 更换为Undertow

Maven配置:

在pom.xml中排除Tomcat依赖,引入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>

Gradle配置:

configurations {
    compile.exclude module: 'spring-boot-starter-tomcat'
}
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-undertow'
}

2. 更换为Jetty

Maven配置:

<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-jetty</artifactId>
</dependency>

Gradle配置:

configurations {
    compile.exclude module: 'spring-boot-starter-tomcat'
}
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-jetty'
}

二、复杂业务与大事务场景下的最优Web服务器

在这类场景下,Undertow是最优选择,原因如下:

  • 采用非阻塞NIO模型,同时支持阻塞IO,在高并发大事务场景下能更高效处理请求,减少线程资源消耗
  • 内存占用远低于Tomcat和Jetty,大事务场景下内存压力更小,降低OOM风险
  • 内置的负载均衡和连接池优化,能更好应对长时间运行的大事务请求,减少连接超时和资源竞争

相比之下:

  • Tomcat虽然生态完善、稳定性高,但资源占用高,高并发大事务下性能下降明显
  • Jetty轻量灵活,但在极端高并发场景下的吞吐量和稳定性不如Undertow

三、Spring Boot Web服务器评估KPI指标

1. 性能指标

  • 吞吐量:单位时间内处理的请求数(如QPS、TPS)
  • 响应时间:平均响应时间、P95/P99响应时间(重点关注大事务请求的响应延迟)
  • 请求处理效率:单个请求的CPU耗时、数据库交互占比

2. 资源占用指标

  • 内存占用:堆内存/非堆内存峰值、GC频率与耗时(大事务场景下需关注内存泄漏风险)
  • CPU使用率:平均CPU使用率、峰值CPU使用率
  • 文件句柄/连接数:活跃连接数、最大连接数使用率

3. 稳定性指标

  • 错误率:HTTP 5xx错误占比、事务失败率
  • 服务可用性:服务在线时长占比、异常重启次数
  • 容错能力:突发流量下的服务降级表现、超时请求占比

4. 并发处理能力

  • 最大并发连接数:服务器能稳定处理的最大并发请求数
  • 连接超时率:大事务场景下的连接超时占比
  • 线程池利用率:核心线程数、最大线程数的使用率,线程阻塞时长

5. 事务相关指标

  • 事务成功率:大事务的提交成功占比
  • 事务平均耗时:事务从开始到提交的平均时长
  • 锁等待时间:大事务中数据库锁、分布式锁的平均等待时长

内容的提问来源于stack exchange,提问作者amir raad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 23:22:14