Tomcat+Undertow+Jetty 的使用及配置调优

SpringBoot的WEB容器使用及配置

注:可查看org.springframework.boot.autoconfigure.web.ServerProperties类

SpringBoot项目中使用Tomcat容器

SpringBoot项目中默认使用的嵌入式Web容器为Tomcat,Maven配置如下即可:
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
SpringBoot项目中Tomcat相关配置
server:
  tomcat:
    accept-count: 1000 		#当所有可能的请求处理线程都在使用时,传入的连接请求的最大队列长度。默认为100
    max-connections: 2000  	#服务器在任何给定时间接受和处理的最大TCP连接数。一旦达到限制,操作系统仍然可以基于“acceptCount”属性接受连接。默认为8192
    max-threads: 300 		#最大线程数,默认200
    min-spare-threads: 50	#最小备用线程数,tomcat启动时的初始化的线程数。
    connection-timeout: 60000  #server端的socket超时间,默认60s, client端设置keepAlive或者server端tcp状态为CLOSE_WAIT(比如client先close),server端判断client端没有读写并且超时时会close掉当前的socket
    max-http-header-size: 1048576  #请求头最大长度kb  
    max-http-post-size: 2097152    #请请求体最大长度kb  POST内容最大长度,默认不限制  
    accesslog:
      enabled: true

SpringBoot项目中使用undertow容器

SpringBoot项目中使用undertow,Maven配置如下:
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- 移除掉默认支持的 Tomcat -->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<!-- 添加 Undertow 容器 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
SpringBoot项目中undertow相关配置
# 是否打开 undertow 日志,默认为 false
server.undertow.accesslog.enabled=false
# 设置访问日志所在目录
server.undertow.accesslog.dir=logs
# 指定工作者线程的 I/0 线程数,默认为 2 或者 CPU 的个数
server.undertow.io-threads=
# 指定工作者线程个数,默认为 I/O 线程个数的 8 倍
server.undertow.worker-threads=
# 设置 HTTP POST 内容的最大长度,默认不做限制
server.undertow.max-http-post-size=0

SpringBoot项目中使用Jetty容器

SpringBoot项目中使用Jetty,Maven配置如下:
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- 移除掉默认支持的 Tomcat -->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<!-- 添加 jetty 依赖 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
SpringBoot项目中undertow相关配置
server:  
  jetty:
    acceptors: -1                       #要使用的接受线程数。当该值为-1(默认值)时,接受器的数量来自操作环境。
    selectors: -1                       #要使用的选择器线程数。当默认值为-1时,选择器的数量来源于操作环境。
    max-threads: 200                    #最大线程数
    min-threads: 8                      #最小线程数
    connection-idle-timeout: 60000ms    #连接在关闭前可以空闲的时间。
    thread-idle-timeout: 60000ms        #最大线程空闲时间。
    accesslog:
      enabled: true    					#是否打开 undertow 日志,默认为 false

注意:

关于三种Web容器的参数配置具体需查看当前项目的org.springframework.boot.autoconfigure.web.ServerProperties类,不同版本的参数可能略有差异。

关于三种Web容器的accesslog日志相关的细节配置需查看当前项目的org.springframework.boot.autoconfigure.web.ServerProperties类

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值