Tomcat线程池梳理

news2025/1/16 0:58:50

Tomcat梳理

文章目录

  • Tomcat梳理
    • 1.问题
    • 2.监控tomcat线程池
      • springboot1.x
      • springboot2.x
      • 转为json格式打印输出
    • 3.SpringBoot内置线程解析测试
      • controller
      • yaml配置
      • 可知ThreadPoolExecutor有如下五种线程池状态。
      • 线程池监控指标
      • 并发测试
        • 并发请求数 <= `Tomcat`最大线程数20
        • 并发请求数 > `Tomcat`最大线程数20
        • 并发请求数大于最大连接数:max-connections
        • 并发请求数大于最大连接数+等待队列大小
    • 总结
    • 总结

1.问题

当Tomcat线程被打满时,可以按照以下步骤进行排查:

1. 查看Tomcat的日志文件,特别是错误日志。在日志中搜索关键字,比如"OutOfMemoryError",以确定是否存在内存溢出异常。
2. 检查Tomcat的JVM参数设置,尤其是内存相关的参数,如-Xmx和-Xms。确保这些参数适当设置,以满足应用的需求。如果需要增加内存,可以调整这些参数的值,并重新启动Tomcat。
3. 使用工具(如jmap、jstack等)获取Tomcat的内存快照和线程堆栈信息,以了解线程的状态和运行情况。这些信息可以帮助确定是否存在线程死锁或长时间运行的线程,从而引起了线程池被打满的问题。
4. 检查Tomcat的配置文件,特别是连接器(Connector)的配置。确保连接器的最大线程数(maxThreads)合理设置,可以根据实际需求适当增加或减少线程数。
5. 检查应用程序的代码,特别是与并发相关的代码块。确保没有出现死锁、线程安全问题或无限循环等导致线程被阻塞的情况。可以使用调试器或性能分析工具来定位问题代码段。
6. 监控服务器的系统资源使用情况,如CPU、内存、磁盘等。如果某个资源被耗尽,可能导致Tomcat线程被打满。可以使用监控工具,如Nagios、Zabbix等,来实时监测服务器资源的使用情况,并进行预警和调整。
7. 在Tomcat集群环境中,检查负载均衡器的配置和运行情况,确保请求能够均匀分发到各个Tomcat节点,避免某一节点负载过高。
8. 如果以上步骤仍然无法解决问题,可以尝试升级Tomcat版本或寻求Tomcat官方或社区的支持。他们可能能提供更具体的调试和排查建议。

总之,当Tomcat线程被打满时,需要综合考虑内存、线程、代码和系统资源等多个因素,并通过逐步排查来定位和解决问题。

2.监控tomcat线程池

springboot1.x

@Autowired
ServletWebServerApplicationContext applicationContext;

TomcatServletWebServerFactory tomcatServletWebServerFactory=applicationContext.getBean(TomcatServletWebServerFactory.class);
String tomcatLog = (((TomcatWebServer)(tomcatServletWebServerFactory.getWebServer())).getTomcat().getConnector()).getProtocolHandler().getExecutor().toString();

打印结果

org.apache.tomcat.util.threads.ThreadPoolExecutor@2a3ffb6f[Running, pool size = 10, active threads = 0, queued tasks = 0, completed tasks = 0]

springboot2.x

	@Autowired
	ServletWebServerApplicationContext applicationContext;
    
	String tomcatLog = ((TomcatWebServer) applicationContext.getWebServer()).getTomcat().getConnector().getProtocolHandler().getExecutor().toString();

打印结果

org.apache.tomcat.util.threads.ThreadPoolExecutor@3a236dad[Running, pool size = 10, active threads = 1, queued tasks = 0, completed tasks = 0]

转为json格式打印输出

@RestController
public class DemoController {
    @Autowired
    ServletWebServerApplicationContext applicationContext;

    @GetMapping("/hs")
    public String test(){
        TomcatServletWebServerFactory tomcatServletWebServerFactory=applicationContext.getBean(TomcatServletWebServerFactory.class);
        String tomcatLog = (((TomcatWebServer)(tomcatServletWebServerFactory.getWebServer())).getTomcat().getConnector()).getProtocolHandler().getExecutor().toString();
        return tomcatLog;
    }


    @GetMapping("/hs2")
    public String test2(){
        String tomcatLog = ((TomcatWebServer) applicationContext.getWebServer()).getTomcat().getConnector().getProtocolHandler().getExecutor().toString();
        return tomcatLog;
    }

    @GetMapping("/hs3")
    public String test3(){
        Executor executor = ((TomcatWebServer) applicationContext.getWebServer()).getTomcat().getConnector().getProtocolHandler().getExecutor();
        return JSON.toJSONString(executor, SerializerFeature.WriteMapNullValue);
    }
}

打印结果

{
	"activeCount": 1,
	"completedTaskCount": 0,
	"corePoolSize": 10,
	"largestPoolSize": 10,
	"maximumPoolSize": 200,
	"poolSize": 10,
	"queue": [],
	"rejectedExecutionHandler": {},
	"shutdown": false,
	"submittedCount": 1,
	"taskCount": 1,
	"terminated": false,
	"terminating": false,
	"threadFactory": {},
	"threadRenewalDelay": 1000
}

3.SpringBoot内置线程解析测试

SpringBoot版本

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

controller

package com.kang.mongodb.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Executor;

/**
 * @Author Emperor Kang
 * @ClassName DemoController
 * @Description TODO
 * @Date 2023/8/21 19:59
 * @Version 1.0
 * @Motto 让营地比你来时更干净
 */
@Slf4j
@RestController
@RequestMapping("/tomcat")
public class TomcatController {
    @Autowired
    ServletWebServerApplicationContext applicationContext;

    /**
     * localhost:10093/tomcat/getString
     * @return
     */
    @RequestMapping("/getString")
    public String getString() {
        try {
            Executor executor = ((TomcatWebServer) applicationContext.getWebServer()).getTomcat().getConnector().getProtocolHandler().getExecutor();
            log.info("{}-{}",Thread.currentThread().getName(), JSON.toJSONString(executor, SerializerFeature.WriteMapNullValue));
            // 将线程挂起3秒,方便观察结果
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "success";
    }

}

yaml配置

server:
  port: 10093
  tomcat:
    accept-count: 5        # 等待队列长度
    threads:
      min-spare: 10        # 最小工作空闲线程数
      max: 20              # 最大线程数
    max-connections: 30    # 最大连接数,一个线程可以处理多个连接

SpringBoot内置tomcat默认配置

SpringBoot内置Tomcat的配置存放在 spring-configuration-metadata.json 文件中,配置以 server.tomcat 开头

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MFRdNFAT-1692699710640)(D:\学习乐园\文档总结\杂记\picture\image-20230822132414766.png)]

最小工作线程数

   {
      "name": "server.tomcat.threads.min-spare",
      "type": "java.lang.Integer",
      "description": "Minimum amount of worker threads:最小工作线程数。",
      "sourceType": "org.springframework.boot.autoconfigure.web.ServerProperties$Tomcat$Threads",
      "defaultValue": 10
    }
  • min-spare:最小备用
# 最小工作空闲线程数,默认10
server.tomcat.threads.min-spare=10

最大工作线程数

    {
      "name": "server.tomcat.threads.max",
      "type": "java.lang.Integer",
      "description": "Maximum amount of worker threads:最大工作线程数",
      "sourceType": "org.springframework.boot.autoconfigure.web.ServerProperties$Tomcat$Threads",
      "defaultValue": 200
    }
# 最大工作线程数,默认200
server.tomcat.threads.max=200

最大连接数

    {
      "name": "server.tomcat.max-connections",
      "type": "java.lang.Integer",
      "description": "Maximum number of connections that the server accepts and processes at any given time. Once the limit has been reached, the operating system may still accept connections based on the \"acceptCount\" property.",
      "sourceType": "org.springframework.boot.autoconfigure.web.ServerProperties$Tomcat",
      "defaultValue": 8192
    }

服务器在任何给定时间内接受和处理的最大连接数。一旦达到该限制,操作系统仍可根据 “acceptCount” 属性接受连接。

# 最大连接数默认是8192
server.tomcat.max-connections=8192

队列长度

    {
      "name": "server.tomcat.accept-count",
      "type": "java.lang.Integer",
      "description": "Maximum queue length for incoming connection requests when all possible request processing threads are in use.",
      "sourceType": "org.springframework.boot.autoconfigure.web.ServerProperties$Tomcat",
      "defaultValue": 100
    }

使用所有可能的请求处理线程时,接收到的连接请求的最大队列长度

# 等待队列长度,默认100
server.tomcat.accept-count=100

总结

参数设置方式默认值含义
acceptCountserver.tomcat.accept-count100接收队列,实质上是在操作系统已经完成三次握手等待accept的socket队列
maxConnectionsserver.tomcat.max-connections8192最大连接数,实质上是指已经accept的socket数量
maxThreadsserver.tomcat.threads.max200用于处理已经accept的socket的线程最大数量
connectionTimeoutserver.tomcat.connection-timeout60000ms是指socket连接后或读取报文字节过程中的超时时间
keepAliveTimeout实现WebServerFactoryCustomizer默认取connectionTimeout在同一个socket连接,处理完一次http请求后,等待下一次http请求的超时时间
MaxKeepAliveRequests实现WebServerFactoryCustomizer100在同一个socket连接,最大处理http请求数量,达到数量后关闭socket

线程的生命周期

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jIspo4yi-1692699710641)(D:\学习乐园\文档总结\杂记\picture\java-thread.jpg)]

可知ThreadPoolExecutor有如下五种线程池状态。

  • RUNNING,线程池接受新任务,会执行任务阻塞队列中的任务,ctl前三位表示为111;
  • SHUTDOWN,线程池拒绝新任务,会执行任务阻塞队列中的任务,ctl前三位表示为000;
  • STOP,线程池拒绝新任务,不会执行任务阻塞队列中的任务,尝试中断正在执行的任务,ctl前三位表示为001;
  • TIDYING,所有任务被关闭,Worker数量为0,ctl前三位表示为010;
  • TERMINATED,terminated() 执行完毕,ctl前三位表示为011。
线程池 的状态说明
RUNNING允许提交并处理任务
SHUTDOWN不允许提交新的任务,但是会处理完已提交的任务
STOP不允许提交新的任务,也不会处理阻塞队列中未执行的任务,
并设置正在执行的线程的中断标志位
TIDYING所有任务执行完毕,池中工作的线程数为0,等待执行terminated()勾子方法
TERMINATEDterminated()勾子方法执行完毕

线程池监控指标

//获取webServer线程池
ThreadPoolExecutor executor = (ThreadPoolExecutor) ((TomcatWebServer) webServerApplicationContext.getWebServer())
        .getTomcat()
        .getConnector()
        .getProtocolHandler()
        .getExecutor();
Map<String, String> returnMap = new LinkedHashMap<>();
returnMap.put("核心线程数", String.valueOf(executor.getCorePoolSize()));
returnMap.put("最大线程数", String.valueOf(executor.getMaximumPoolSize()));
returnMap.put("活跃线程数", String.valueOf(executor.getActiveCount()));
returnMap.put("池中当前线程数", String.valueOf(executor.getPoolSize()));
returnMap.put("历史最大线程数", String.valueOf(executor.getLargestPoolSize()));
returnMap.put("线程允许空闲时间/s", String.valueOf(executor.getKeepAliveTime(TimeUnit.SECONDS)));
returnMap.put("核心线程数是否允许被回收", String.valueOf(executor.allowsCoreThreadTimeOut()));
returnMap.put("提交任务总数", String.valueOf(executor.getSubmittedCount()));
returnMap.put("历史执行任务的总数(近似值)", String.valueOf(executor.getTaskCount()));
returnMap.put("历史完成任务的总数(近似值)", String.valueOf(executor.getCompletedTaskCount()));
returnMap.put("工作队列任务数量", String.valueOf(executor.getQueue().size()));
returnMap.put("拒绝策略", executor.getRejectedExecutionHandler().getClass().getSimpleName());

并发测试

并发请求数 <= Tomcat最大线程数20

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-nlO7SAcx-1692699710642)(D:\学习乐园\文档总结\杂记\picture\image-20230822155019481.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PfyPePxe-1692699710642)(D:\学习乐园\文档总结\杂记\picture\image-20230822155146584.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-qXVwHKYa-1692699710643)(D:\学习乐园\文档总结\杂记\picture\image-20230822155300727.png)]

当请求量小于等于tomcat最大线程数时

  • 全部请求都正常,没有失败
  • 从结果可以看到越是靠后的线程,连接时间和处理时间都增长了,说明随着线程数增多性能下降了

tomcat线程池监控日志打印

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ALvEf29y-1692699710644)(D:\学习乐园\文档总结\杂记\picture\image-20230822155717786.png)]

http-nio-10093-exec-5-{"activeCount":6,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":10,"maximumPoolSize":20,"poolSize":10,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":6,"taskCount":6,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-6-{"activeCount":6,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":10,"maximumPoolSize":20,"poolSize":10,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":6,"taskCount":6,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-1-{"activeCount":6,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":10,"maximumPoolSize":20,"poolSize":10,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":6,"taskCount":6,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-4-{"activeCount":6,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":10,"maximumPoolSize":20,"poolSize":10,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":6,"taskCount":6,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-2-{"activeCount":6,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":10,"maximumPoolSize":20,"poolSize":10,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":6,"taskCount":6,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-3-{"activeCount":6,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":10,"maximumPoolSize":20,"poolSize":10,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":6,"taskCount":6,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-8-{"activeCount":15,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":17,"maximumPoolSize":20,"poolSize":17,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":18,"taskCount":18,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-10-{"activeCount":16,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":16,"maximumPoolSize":20,"poolSize":16,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":16,"taskCount":19,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-7-{"activeCount":15,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":16,"maximumPoolSize":20,"poolSize":16,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":16,"taskCount":16,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-9-{"activeCount":16,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":16,"maximumPoolSize":20,"poolSize":16,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":17,"taskCount":17,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-14-{"activeCount":19,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":19,"maximumPoolSize":20,"poolSize":19,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":19,"taskCount":19,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-13-{"activeCount":19,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":19,"maximumPoolSize":20,"poolSize":19,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":19,"taskCount":19,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-11-{"activeCount":19,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":19,"maximumPoolSize":20,"poolSize":19,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":19,"taskCount":19,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-12-{"activeCount":19,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":19,"maximumPoolSize":20,"poolSize":19,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":19,"taskCount":19,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-15-{"activeCount":19,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":19,"maximumPoolSize":20,"poolSize":19,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":19,"taskCount":19,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-17-{"activeCount":19,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":19,"maximumPoolSize":20,"poolSize":19,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":19,"taskCount":19,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-16-{"activeCount":19,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":19,"maximumPoolSize":20,"poolSize":19,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":19,"taskCount":19,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-18-{"activeCount":19,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":19,"maximumPoolSize":20,"poolSize":19,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":19,"taskCount":19,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-19-{"activeCount":19,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":19,"maximumPoolSize":20,"poolSize":19,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":19,"taskCount":19,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-20-{"activeCount":20,"completedTaskCount":0,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":20,"taskCount":20,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}

并发请求数 > Tomcat最大线程数20

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-9sqbeBjy-1692699710644)(D:\学习乐园\文档总结\杂记\picture\image-20230822160140866.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UBm1jFi5-1692699710645)(D:\学习乐园\文档总结\杂记\picture\image-20230822164011595.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ff8XAyoP-1692699710645)(D:\学习乐园\文档总结\杂记\picture\image-20230822164108200.png)]

当请求量大于tomcat最大线程数时

  • 可以看到前20个请求都在3s的时间左右完成了,但是后五个因为没有线程资源去处理只能等到这20个线程资源被释放后才能执行这几个线程,所以后面五个都是6s多才执行完成
  • 从聚合数据分析来看,我们如果不修改tomcat的配置,随着请求量的增多,系统的吞吐量是下降的

tomcat线程池监控日志打印

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xc9V5HEa-1692699710646)(D:\学习乐园\文档总结\杂记\picture\image-20230822170024716.png)]

http-nio-10093-exec-4-{"activeCount":1,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":10,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":8,"taskCount":40,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-16-{"activeCount":4,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":10,"queue":[{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":14,"taskCount":46,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-17-{"activeCount":4,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":10,"queue":[{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":15,"taskCount":47,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-21-{"activeCount":12,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":15,"queue":[{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":15,"taskCount":47,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-18-{"activeCount":11,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":14,"queue":[{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":15,"taskCount":47,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-1-{"activeCount":16,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":16,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":16,"taskCount":49,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-24-{"activeCount":16,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":16,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":17,"taskCount":49,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-2-{"activeCount":17,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":17,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":17,"taskCount":50,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-20-{"activeCount":17,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":17,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":17,"taskCount":50,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-19-{"activeCount":17,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":17,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":17,"taskCount":50,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-12-{"activeCount":4,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":10,"queue":[{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":17,"taskCount":50,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-13-{"activeCount":17,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":17,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":17,"taskCount":50,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-22-{"activeCount":17,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":17,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":17,"taskCount":50,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-26-{"activeCount":17,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":17,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":17,"taskCount":50,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-25-{"activeCount":17,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":17,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":17,"taskCount":50,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-27-{"activeCount":17,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":17,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":17,"taskCount":50,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-23-{"activeCount":17,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":17,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":17,"taskCount":50,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-30-{"activeCount":20,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":24,"taskCount":57,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-28-{"activeCount":20,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":24,"taskCount":57,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-29-{"activeCount":20,"completedTaskCount":33,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":24,"taskCount":57,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-21-{"activeCount":16,"completedTaskCount":44,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":15,"taskCount":60,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-20-{"activeCount":16,"completedTaskCount":44,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":15,"taskCount":60,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-4-{"activeCount":16,"completedTaskCount":45,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":13,"taskCount":60,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-23-{"activeCount":17,"completedTaskCount":45,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":11,"taskCount":60,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-1-{"activeCount":17,"completedTaskCount":44,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":11,"taskCount":60,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}

挑几个典型的说说

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uPAucIZS-1692699710646)(D:\学习乐园\文档总结\杂记\picture\image-20230822170736947.png)]

  • poolSize:池中当前线程10,15,都已经达到最小空闲线程数的设置了,那么后面队列中排队的大小,就是加入队列等待处理的请求
  • submittedCount:提交的任务数,可以看到队列中有排队的,提交的任务数14,15,15,所以后面的五个必须要等到有线程资源的时候才可以去执行

并发请求数大于最大连接数:max-connections

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5ctVOLtH-1692699710647)(D:\学习乐园\文档总结\杂记\picture\image-20230822171923467.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pQyugIcC-1692699710647)(D:\学习乐园\文档总结\杂记\picture\image-20230822171825869.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QKdwfzBJ-1692699710648)(D:\学习乐园\文档总结\杂记\picture\image-20230822172253376.png)]

并发请求数大于最大连接数:max-connections

  • 所有的请求都执行成功了,后面的15个请求都需要等待线程资源释放后才会去处理,所以从上面可以看到我们的处理时长后面的都是6S多
  • 有意思的是我们的吞吐量反而增加了,因为大量的线程被同时释放,所以大量排队的请求被处理了,从而增加了我们的吞吐量
  • 注意:连接是由线程去处理的,所以连接在等待线程,而不是线程等待连接(并发请求量大的时候)

tomcat线程池监控日志打印

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-c04LkUWp-1692699710649)(D:\学习乐园\文档总结\杂记\picture\image-20230822172627156.png)]

http-nio-10093-exec-25-{"activeCount":3,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":10,"queue":[{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":8,"taskCount":91,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-26-{"activeCount":5,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":10,"queue":[{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":8,"taskCount":91,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-21-{"activeCount":5,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":10,"queue":[{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":8,"taskCount":91,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-16-{"activeCount":8,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":13,"queue":[{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":13,"taskCount":96,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-13-{"activeCount":8,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":13,"queue":[{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":14,"taskCount":97,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-1-{"activeCount":19,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":22,"taskCount":105,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-20-{"activeCount":19,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":22,"taskCount":105,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-4-{"activeCount":19,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":22,"taskCount":105,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-23-{"activeCount":20,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":26,"taskCount":109,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-2-{"activeCount":20,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":26,"taskCount":109,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-38-{"activeCount":20,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":26,"taskCount":109,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-31-{"activeCount":20,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":26,"taskCount":109,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-36-{"activeCount":20,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":26,"taskCount":109,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-39-{"activeCount":20,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":26,"taskCount":109,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-34-{"activeCount":20,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":26,"taskCount":109,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-32-{"activeCount":20,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":26,"taskCount":109,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-37-{"activeCount":20,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":26,"taskCount":109,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-33-{"activeCount":20,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":26,"taskCount":109,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-35-{"activeCount":20,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":26,"taskCount":109,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-40-{"activeCount":20,"completedTaskCount":83,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":26,"taskCount":109,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-13-{"activeCount":20,"completedTaskCount":88,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":25,"taskCount":113,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-16-{"activeCount":20,"completedTaskCount":88,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":25,"taskCount":113,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-21-{"activeCount":20,"completedTaskCount":88,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":25,"taskCount":113,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-25-{"activeCount":20,"completedTaskCount":88,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":25,"taskCount":113,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-26-{"activeCount":20,"completedTaskCount":88,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":25,"taskCount":113,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-36-{"activeCount":18,"completedTaskCount":105,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":20,"taskCount":126,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-37-{"activeCount":20,"completedTaskCount":100,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":20,"taskCount":127,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-39-{"activeCount":20,"completedTaskCount":100,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":20,"taskCount":126,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-20-{"activeCount":20,"completedTaskCount":99,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{},{},{},{},{},{},{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":23,"taskCount":126,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-38-{"activeCount":16,"completedTaskCount":114,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[{}],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":14,"taskCount":133,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-33-{"activeCount":15,"completedTaskCount":122,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":15,"taskCount":137,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-4-{"activeCount":15,"completedTaskCount":122,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":15,"taskCount":137,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-31-{"activeCount":15,"completedTaskCount":122,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":15,"taskCount":137,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-34-{"activeCount":15,"completedTaskCount":122,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":15,"taskCount":137,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}
http-nio-10093-exec-32-{"activeCount":15,"completedTaskCount":122,"corePoolSize":10,"largestPoolSize":20,"maximumPoolSize":20,"poolSize":20,"queue":[],"rejectedExecutionHandler":{},"shutdown":false,"submittedCount":15,"taskCount":137,"terminated":false,"terminating":false,"threadFactory":{},"threadRenewalDelay":1000}

并发请求数大于最大连接数+等待队列大小

  • 30+5=35

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-yNS4gdct-1692699710649)(D:\学习乐园\文档总结\杂记\picture\image-20230822173339477.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PWLWOhpd-1692699710650)(D:\学习乐园\文档总结\杂记\picture\image-20230822173547029.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-hcDpYffG-1692699710650)(D:\学习乐园\文档总结\杂记\picture\image-20230822173625006.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-NCc0qJOd-1692699710650)(D:\学习乐园\文档总结\杂记\picture\image-20230822174048768.png)]

并发请求数大于最大连接数+等待队列大小

  • 我们请求量是45,但是我们tomcat能接收的最大请求为最大连接数+等待队列大小:30+5=35,所以我们发现有10个请求被拒绝了
  • Response code:Non HTTP response code: org.apache.http.conn.HttpHostConnectException
  • Response message:Non HTTP response message: Connect to 127.0.0.1:10093 [/127.0.0.1] failed: Connection refused: connect
  • 但是这种情况并不绝对,因为连接是由线程去处理的,因为每个请求过来肯定是尝试连接,一直尝试,我们可以看到,只有尝试时间很长的才失败了,但是很多尝试连接成功的,就被释放的线程资源去处理了,比如我把请求数设置40,结果如下

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vF0YambF-1692699710651)(D:\学习乐园\文档总结\杂记\picture\image-20230822175634542.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mjpS1fjV-1692699710651)(D:\学习乐园\文档总结\杂记\picture\image-20230822175656805.png)]

  • 我们发现发起了40个请求,理论上应该是35个成功,5个失败,但是我们看到,他有这个尝试机制,只要连接成功了,并且有线程资源处理他就会执行返回

总结

  • 最大连接数:每个Http请求占用一个连接
  • 等待队列长度:Http请求数超过最大连接数时,多出的请求会放入等待队列,如果队列也满了请求会被丢弃。所以Tomcat能接收的请求数为最大连接数+等待队列长度
  • 最大线程数:Tomcat最多能同时处理的请求数,比如有30个请求,但是最大线程数为20,那么同时有20个请求可以被处理
  • 但是这种情况并不绝对,因为连接是由线程去处理的,因为每个请求过来肯定是尝试连接,一直尝试,我们可以看到,只有尝试时间很长的才失败了,但是很多尝试连接成功的,就被释放的线程资源去处理了,比如我把请求数设置40,结果如下

[外链图片转存中...(img-vF0YambF-1692699710651)]

[外链图片转存中...(img-mjpS1fjV-1692699710651)]

  • 我们发现发起了40个请求,理论上应该是35个成功,5个失败,但是我们看到,他有这个尝试机制,只要连接成功了,并且有线程资源处理他就会执行返回

总结

  • 最大连接数:每个Http请求占用一个连接
  • 等待队列长度:Http请求数超过最大连接数时,多出的请求会放入等待队列,如果队列也满了请求会被丢弃。所以Tomcat能接收的请求数为最大连接数+等待队列长度
  • 最大线程数:Tomcat最多能同时处理的请求数,比如有30个请求,但是最大线程数为20,那么同时有20个请求可以被处理

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/914861.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

AcWing算法基础课第四讲动态规划(2): 线性DP、区间DP

文章目录 &#xff08;1&#xff09;线性DP898. 数字三角形895. 最长上升子序列897. 最长公共子序列 &#xff08;2) 区间DP282. 石子合并区间 DP 常用模版 &#xff08;1&#xff09;线性DP 898. 数字三角形 题目链接 给定一个如下图所示的数字三角形&#xff0c;从顶部出发…

蒙蒂卡洛与圣杯:二次更快的模拟

一、说明 针对不确知的&#xff0c;或者是 混沌问题&#xff0c;如果存在解决&#xff0c;什么方法最有效&#xff1f;本文针对蒙特卡洛法展开讨论。 你有没有试过把一个糟糕的糖果包装纸扔进垃圾桶&#xff0c;即使你把它正好放在垃圾箱上方&#xff0c;皱巴巴的塑料也很可能会…

【AIGC】AI工具合集人脸动漫化,老照片修复和视频补帧工具

Paper2GUI: 一款面向普通人的 AI 桌面 APP 工具箱&#xff0c;免安装即开即用&#xff0c;已支持 40AI 模型&#xff0c;内容涵盖 AI 绘画、语音合成、视频补帧、视频超分、目标检测、图片风格化、OCR 识别等领域。支持 Windows、Mac、Linux 系统。 小白兔AI 3.0版起永久免费A…

【Git Bash】简明从零教学

目录 Git 的作用官网介绍简明概要 Git 下载链接Git 的初始配置配置用户初始化本地库 Git 状态查询Git 工作机制本地工作机制远端工作机制 Git 的本地管理操作add 将修改添加至暂存区commit 将暂存区提交至本地仓库日志查询版本穿梭 Git 分支查看分支创建与切换分支跨分支修改与…

变压器绝缘油介质损耗因素测试

试验目的 变压器油又称绝缘油&#xff0c;是一种电介质&#xff0c;是能够耐受电应力的绝缘体。当对介质油施加交流电压时&#xff0c;所通过的电流与其两端的电压相位差并不是90度角&#xff0c;而是比90度角要小一个δ角的&#xff0c;此δ角称为油的介质损耗角。变压器油的…

微服务集成spring cloud sentinel

目录 1. sentinel使用场景 2. sentinel组成 3. sentinel dashboard搭建 4. sentinel客户端详细使用 4.1 引入依赖 4.2 application.properties增加dashboard注册地址 4.3 手动增加限流配置类 4.4 rest接口及service类 4.5 通过dashboard动态配置限流规则 1. sentinel使…

Linux 系统下 GDB 调试器的使用

文章目录 简介GDB 的介绍GDB 的使用 GDB 常用命令及示例查看相关操作断点相关操作运行相关操作变量相关操作分隔窗口操作 简介 GDB 的介绍 GDB 是 GNU 调试程序&#xff0c;是用来调试 C 和 C 程序的调试器。它可以让程序开发者在程序运行时观察程序的内部结构和内存的使用情况…

大数据时代,个人信息数据库保护的挑战及其对策

挑战&#xff1a; 数据泄露&#xff1a;大数据时代&#xff0c;个人信息数据库面临被黑客攻击、内部员工滥用权限等风险&#xff0c;导致个人信息泄露的风险增加。 隐私保护&#xff1a;随着大数据的快速发展&#xff0c;个人信息的采集和分析变得更加广泛和深入。但是&#xf…

初级工程师职称评定条件及流程是什么呢?初级作用是什么?

现在全国统一的助理&#xff08;初级&#xff09;工程师是由人社部颁发的初级工程师证也就是大家说的初级职称。人社部备案&#xff0c;正规可靠&#xff0c;国家认可&#xff0c;评审表、红头文件齐全&#xff0c;可以用于应聘、在职、上岗、加薪、评级、评职称或者企业升资质…

indexDB入门到精通

前言 由于开发3D可视化项目经常用到模型&#xff0c;而一个模型通常是几m甚至是几十m的大小对于一般的服务器来讲加载速度真的十分的慢&#xff0c;为了解决这个加载速度的问题&#xff0c;我想到了几个本地存储的。 首先是cookie,cookie肯定是不行的&#xff0c;因为最多以只…

MPP 还是主流架构吗

MPP 架构&#xff1a; MPP 架构的产品&#xff1a; Impala ClickHouse Druid Doris 很多 OLAP 引擎都采用了 MPP 架构 批处理系统 - 使用场景分钟级、小时级以上的任务&#xff0c;目前很多大型互联网公司都大规模运行这样的系统&#xff0c;稳定可靠&#xff0c;低成本。…

9.1 功率放大电路概述

在实用电路中&#xff0c;往往要求放大电路的末级&#xff08;即输出级&#xff09;输出一定的功率&#xff0c;以驱动负载。能够向负载提供足够信号功率的放大电路称为功率放大电路&#xff0c;简称功放。从能量控制和转换的角度看&#xff0c;功率放大电路与其它放大电路在本…

c++ qt--信号与槽(二) (第四部分)

c qt–信号与槽(二) &#xff08;第四部分&#xff09; 一.信号与槽的关系 1.一对一 2.一对多 3.多对一 4.多对多 还可以进行传递 信号->信号->槽 一个信号控制多个槽的例子&#xff08;通过水平滑块控制两个组件&#xff09; 1.应用的组件 注意这里最下面的组件…

MongoDB快速上手

MongoDB快速上手 MongoDB用起来-快速上手&集群和安全系列 课程目标&#xff1a; 理解MongoDB的业务场景、熟悉MongoDB的简介、特点和体系结构、数据类型等能够在windows和linux下安装和启动MongoDB、图形化管理界面Compass的安装使用掌握MongoDB基本常用命令实现数据的C…

mysql 、sql server 临时表、表变量、

sql server 临时表 、表变量 mysql 临时表 创建临时表 create temporary table 表名 select 字段 [&#xff0c;字段2…&#xff0c;字段n] from 表

项目解决问题

红外 没接收到红外信号时&#xff0c; 会有杂波干扰 STC单片机 STC的串口要用一个定时器作为波特率发生器 开定时器2需要 开定时器0 1 要ET0 1 ET11打开 串口有时候和定时器有冲突 串口发送函数放定时器中断函数中&#xff0c;时间太少可能会导致一直卡在定时器中AUXR | 0x…

精彩回顾 | 风丘科技亮相2023中国汽车测试及质量监控博览会

2023年8月9-11日&#xff0c;风丘科技携手德国Softing、德国IPETRONIK亮相中国汽车测试及质量监控博览会&#xff08;2023 Testing Expo&#xff09;&#xff0c;为大家呈现了在汽车测试、车辆诊断领域里专业的研发测试工具及创新解决方案&#xff0c;吸引了众多客户驻足洽谈。…

MySQL基础篇(四)

多表查询 概述&#xff1a;多表查询就是多张表之间的查询。 回顾&#xff1a;SELECT * FROM table_name 多表查询 from 后面就得跟多张表。如&#xff1a;select * from emp,dept 笛卡尔积&#xff1a;笛卡尔积在数学中&#xff0c;表示两个集合&#xff0c;集合 A 和集合 B…

解决`idea`中`database`工具查询起别名乱码问题

文章目录 解决idea中database工具查询起别名乱码问题场景复现如何解决方式一 设置编码方式二&#xff1a;修改字体 原因说明 解决idea中database工具查询起别名乱码问题 场景复现 使用Idea做查询的并且起别名出现了中文乱码 如何解决 方式一 设置编码 settings->输入框输…

算法-滑动窗口-串联所有单词的子串

算法-滑动窗口-串联所有单词的子串 1 题目概述 1.1 题目出处 https://leetcode.cn/problems/substring-with-concatenation-of-all-words/ 1.2 题目描述 2 滑动窗口Hash表 2.1 解题思路 构建一个大小为串联子串的总长的滑动窗口为每个words中的子串创建一个hash表, <子…