开发者

SpringBoot服务器配置全过程

开发者 https://www.devze.com 2025-11-15 10:23 出处:网络 作者: tomorrow.hello
目录1. SpringBoot Header2.SpringBoot 默认同时可以处理的最大连接数Tomcat(默认服务器)JettyUndertow总结1. SpringBoot Header
目录
  • 1. SpringBoot Header
  • 2.SpringBoot 默认同时可以处理的最大连接数
    • Tomcat(默认服务器)
    • Jetty
    • Undertow
  • 总结

    1. SpringBoot Header

    Springboot默认header的最大长度是8KB。通过

    org.springframework.boot.autoconfigure.web.ServerProperties可以看到

    SpringBoot服务器配置全过程

    SpringBoot服务器配置全过程

    在SpringBoot中,可以在配置文件中修改请求头最大限制。

    在propertdwnxjvies文件中:

    server.maxhttprequestheadersize=100MB

    2.SpringBoot 默认同时可以处理的最大连接数

    Spring Boot 的默认最大连接数取决于其内置的服务器(如 Tomcat、Jetty 或 Undertow)以及相关配置。

    Tomcat(默认服务器)

    通过org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat分析

    SpringBoot服务器配置全过程

    Spring Boot 2.x/3.x 默认使用 Tomcat,其核心连接参数如下:

    • 最大连接数(maxConnections):8192(Tomcat 10+ 默认值)

    含义:服务器可接受的最大连接数(包括等待处理的连接)。

    • 最大工作线程数(maxThreads):200

    含义:同时处理请求的最大线程数。

    • 最大等待队列长度(acceptCount):100

    含义:当所有线程都在处理请求时,可放入队列等待的最DWnxjv大请求数。

    修改配置:

    server.tomcat.maxthreads=500
    server.tomcat.maxconnections=10000
    server.tomcat.acceptcount=200
    

    Jetty

    通过org.springframework编程客栈.boot.autoconfigure.web.ServerProperties.Jetty分析

    SpringBoot服务器配置全过程

    SpringBoot服务器配置全过程

    • 最大连接数(maxConnections):无上限
    • 最大工作线程数(maxThreads):200
    • 最大队列长度(acceptQueueSize):无上限

    设置Jetty:

    server.jetty.threads.max=200
    server.jetty.threads.min=8
    server.jetty.threads.idletimeout=60000ms
    serve编程客栈r.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   # 缓冲区大小
    

    SpringBoot服务器配置全过程

    总结

    以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程客栈(www.devze.com)。

    0

    精彩评论

    暂无评论...
    验证码 换一张
    取 消

    关注公众号