SpringBoot服务器配置全过程
作者:tomorrow.hello
Spring Boot默认请求头最大长度为8KB,可以通过配置文件修改,默认最大连接数取决于所用服务器(如Tomcat、Jetty或Undertow),例如Tomcat默认最大连接数为8192,最大工作线程数为200,最大等待队列长度为100,Jetty和Undertow也有不同的默认配置
1. SpringBoot Header
Springboot默认header的最大长度是8KB。通过
org.springframework.boot.autoconfigure.web.ServerProperties可以看到


在SpringBoot中,可以在配置文件中修改请求头最大限制。
在properties文件中:
server.maxhttprequestheadersize=100MB
2.SpringBoot 默认同时可以处理的最大连接数
Spring Boot 的默认最大连接数取决于其内置的服务器(如 Tomcat、Jetty 或 Undertow)以及相关配置。
Tomcat(默认服务器)
通过org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat分析

Spring Boot 2.x/3.x 默认使用 Tomcat,其核心连接参数如下:
- 最大连接数(maxConnections):8192(Tomcat 10+ 默认值)
含义:服务器可接受的最大连接数(包括等待处理的连接)。
- 最大工作线程数(maxThreads):200
含义:同时处理请求的最大线程数。
- 最大等待队列长度(acceptCount):100
含义:当所有线程都在处理请求时,可放入队列等待的最大请求数。
修改配置:
server.tomcat.maxthreads=500 server.tomcat.maxconnections=10000 server.tomcat.acceptcount=200
Jetty
通过org.springframework.boot.autoconfigure.web.ServerProperties.Jetty分析


- 最大连接数(maxConnections):无上限
- 最大工作线程数(maxThreads):200
- 最大队列长度(acceptQueueSize):无上限
设置Jetty:
server.jetty.threads.max=200 server.jetty.threads.min=8 server.jetty.threads.idletimeout=60000ms server.jetty.maxconnections=8192
Undertow
最大工作线程数(io-threads × worker-threads):
- io-threads:2 × CPU核心数(默认)
- worker-threads:200(默认)
- 总线程数 = io-threads × worker-threads
每个连接的直接缓冲区大小(direct-buffers):true(默认启用)
server.undertow.threads.io=8# I/O线程数(默认CPU核心数×2) server.undertow.threads.worker=256 # 工作线程数 server.undertow.buffersize=1024 # 缓冲区大小

总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
