2026/3/30 1:05:02
网站建设
项目流程
制作微信公众号网站开发,wordpress搜索收录,ideo设计公司官网,网站建设服务协议书把 Spring Boot 默认的 Tomcat 换成 Undertow#xff0c;空载就能少 20 %–30 %#xff0c;生产环境普遍能省 60-100 MB RSS#xff0c;极限优化#xff08;再调线程 关无用特性#xff09;能把 1.8 G 直接压到 1.1 G#xff0c;降幅接近 40 %。下面把社区最新实测数据拆…把 Spring Boot 默认的 Tomcat 换成 Undertow空载就能少 20 %–30 %生产环境普遍能省 60-100 MB RSS极限优化再调线程 关无用特性能把 1.8 G 直接压到 1.1 G降幅接近 40 %。下面把社区最新实测数据拆开给你看。---一、空载对比只引了 spring-webHelloController指标 Tomcat Undertow 降幅启动后堆 60-80 MB 40-60 MB ↓25 %Metaspace 40-50 MB 25-35 MB ↓35 %非堆/代码缓存 70-90 MB 50-70 MB ↓28 %RSS 总计 180-250 MB 120-180 MB ↓25-30 %---二、压测对比4 核 8 GWRK 4 k 并发 30 s场景 TPS 99 %延迟 RSS 省内存Tomcat 默认 11 k 210 ms 1.8 G –Undertow 优化 25 k 98 ms 1.1 G ↓39 %优化指io-threads4worker-threads20压缩开关闭 session、jsp、websocket 等用不到的子系统。---三、线程模型带来的“隐藏”内存Tomcat 默认 200 工作线程每条 1 MB 栈 ≈ 200 MB 虚拟内存Undertow 官方建议 worker-threads CPU*88 核也就 64 条仅栈就省 130 MB 左右。---四、实际落地步骤3 行搞定1. 换依赖xmldependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactIdexclusionsexclusiongroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-tomcat/artifactId/exclusion/exclusions/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-undertow/artifactId/dependency2. 调线程application.ymlyamlserver.undertow.io-threads: 4server.undertow.worker-threads: 20 # 根据实际 QPS 再微调server.compression.enabled: true3. 把用不到的子系统关掉可选javaBeanpublic UndertowServletWebServerFactory factory() {UndertowServletWebServerFactory f new UndertowServletWebServerFactory();f.addDeploymentInfoCustomizers(info - {info.setDisableSessionIdReuse(true); // 无会话info.setDefaultSessionTimeout(0);});return f;}做完直接 docker stats 看 RSS普遍再掉 60-100 MB。---结论“换 Undertow” 是最具性价比的一次改动零业务代码、无感切换、空载省 25 %压测省 40 %如果再把线程池、session、websocket 等一并裁剪整体内存降幅 30-40 % 是稳的。