Tomcat线程池梳理

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个请求可以被处理

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

聊聊 Docker

聊聊 Docker Docker 是什么&#xff1f; 定义 Docker 是一款 开源的应用容器引擎。 简单来说&#xff0c;就是 以容器虚拟化技术为基础的软件。可以把应用程序和所依赖的包一起打包到一个可移植的镜像中&#xff0c;发布到 Linux 或者 Windows 上运行。&#xff08;代码 运…

从零开始学习YOLOv5 保姆级教程

一、前言 YOLO系列是one-stage且是基于深度学习的回归方法&#xff0c;而R-CNN、Fast-RCNN、Faster-RCNN等是two-stage且是基于深度学习的分类方法。 YOLOv5是一种单阶段目标检测算法&#xff0c;该算法在YOLOv4的基础上添加了一些新的改进思路&#xff0c;使其速度与精度都得…

使用 wxPython 和 pymupdf进行 PDF 加密

PDF 文件是一种常见的文档格式&#xff0c;但有时候我们希望对敏感信息进行保护&#xff0c;以防止未经授权的访问。在本文中&#xff0c;我们将使用 Python 和 wxPython 库创建一个简单的图形用户界面&#xff08;GUI&#xff09;应用程序&#xff0c;用于对 PDF 文件进行加密…

Lua之Lua源文件批量转换为luac字节码文件

准备的工具&#xff1a;luac.exe CSDNhttps://mp.csdn.net/mp_download/manage/download/UpDetailed Unity版: using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine;public static class Bat…

前端开发中移动端开发需要注意什么? - 易智编译EaseEditing

在前端开发中&#xff0c;移动端开发具有一些独特的挑战和注意事项。以下是移动端开发时需要注意的一些重要点&#xff1a; 响应式设计&#xff1a; 移动设备的屏幕尺寸和分辨率多样&#xff0c;因此要采用响应式设计&#xff0c;确保你的网站或应用在各种设备上都能良好地呈…

基于学习交流社区的自动化测试实现

一 项目介绍 项目名称 项目展示链接&#xff1a; 学习交流社区 项目介绍 项目介绍&#xff1a; 学习交流社区是一个基于Spring的前后端分离的在线论坛系统。使用了MySQL数据库来存储相关信息&#xff0c;项目完成后使用Xshell将其部署到云服务器上。 前端页面&#xff1a; 前端…

实时云渲染的关键技术是什么

首先&#xff0c;我们需要了解实时云渲染的概念。实时云渲染是指将原本在本地电脑上进行的渲染工作转移到云端服务器上完成&#xff0c;并实时将处理结果返回给终端用户显示。这其实是一个合成词&#xff0c;由实时、云和渲染三个关键词组成。实时表示具有时效性和同步效果&…

09 数据库开发-MySQL

文章目录 1 数据库概述2 MySQL概述2.1 MySQL安装2.1.1 解压&添加环境变量2.1.2 初始化MySQL2.1.3 注册MySQL服务2.1.4 启动MySQL服务2.1.5 修改默认账户密码2.1.6 登录MySQL 2.2 卸载MySQL2.3 连接服务器上部署的数据库2.4 数据模型2.5 SQL简介2.5.1 SQL通用语法2.3.2 分类…

ES搭建集群

一、创建 elasticsearch-cluster 文件夹 创建 elasticsearch-7.8.0-cluster 文件夹&#xff0c;在内部复制三个 elasticsearch 服务。 然后每个文件目录中每个节点的 config/elasticsearch.yml 配置文件 node-1001 节点 #节点 1 的配置信息&#xff1a; #集群名称&#xff0…

用断言更好地实现替换重复出现的单词

断言是指对匹配到的文本位置有要求。也就是说&#xff0c;在有些情况下&#xff0c;我们对要匹配的文本的位置也有一定的要求。为了解决这个问题&#xff0c;正则中提供了一些结构&#xff0c;只用于匹配位置&#xff0c;而不是文本内容本身&#xff0c;这种结构就是断言。常见…

【踩坑日记】STM32 USART 串口与 FreeRTOS 冲突

文章目录 问题描述问题出现的环境问题解决过程第一步第二步第三步第四步第五步第六步第七步第八步 后续验证一些思考类似的问题后记 问题描述 笔者使用 FreeRTOS 创建了两个任务&#xff0c;使两颗 LED 以不同频率闪烁&#xff0c;但是在加入串口 USART 部分代码后&#xff0c…

【Linux】线程篇Ⅰ:线程和task_struct 执行流的理解、相关接口命令、线程异常、线程的私有和共享

线程Ⅰ 一、概念0. 线程1. 线程的优缺点2. 页框和页帧3. 页表的设计、虚拟地址的解析方式、以及块为什么设计成 4kb4. 对进程的一些整体理解 二、一些接口 和 命令1. ps -aL - - 查看执行流2. pthread_create 函数&#xff1a;创建线程3. ptread_join 线程等待4. ptread_exit 线…

简单计算器的实现(含转移表实现)

文章目录 计算器的一般实现使⽤函数指针数组的实现&#xff08;转移表&#xff09; 计算器的一般实现 通过函数的调用&#xff0c;实现加减乘除 # define _CRT_SECURE_NO_WARNINGS#include<stdio.h>int Add(int x, int y) {return x y; }int Sub(int x, int y) {retur…

变频器和plc之间无线MODBUS通讯

在工业现场由PLC远程控制变频器的应用非常常见&#xff0c;如果挖沟布线不便或者变频器在移动设备上&#xff0c;那么采用无线通讯就是最佳方案。 这里我们选用最常用的三菱 FX2N PLC和三菱变频器为例&#xff0c;并结合日系plc专用无线通讯终端DTD435M来说明PLC与变频器之间的…

# Lua与C++交互(二)———— 交互

C 调用lua 基础调用 再来温习一下 myName “beauty girl” C想要获取myName的值&#xff0c;根据规则&#xff0c;它需要把myName压入栈中&#xff0c;这样lua就能看到&#xff1b;lua从堆栈中获取myName的值&#xff0c;此时栈顶为空&#xff1b;lua拿着myName去全局表中查…

C++进阶 多线程相关

本篇博客介绍&#xff1a; 主要介绍C中的一些线程操作以及线程库 C进阶 多线程相关 为什么要有线程库线程库介绍线程库常见的接口构造线程对象获取线程idjoin和deteach mutex库原子操作相关条件变量库总结 为什么要有线程库 我们在Linux中写多线程的时候使用的是Linux下提供的…

怎样做好数字营销呢?

2023 年&#xff0c;数字营销将随着新技术、趋势和消费者行为的不断发展而不断发展。要在 2023 年在数字营销领域取得成功&#xff0c;请考虑以下策略&#xff1a; 1.内容质量和个性化&#xff1a; 专注于制作与目标受众产生共鸣的高质量且相关的内容。 根据用户偏好、行为和…

【健康医疗】Axure用药提醒小程序原型图,健康管理用药助手原型模板

作品概况 页面数量&#xff1a;共 20 页 兼容软件&#xff1a;Axure RP 9/10&#xff0c;不支持低版本 应用领域&#xff1a;健康管理&#xff0c;用药助手 作品申明&#xff1a;页面内容仅用于功能演示&#xff0c;无实际功能 作品特色 本作品为「用药提醒」小程序原型图…

【VS】InstallerProjects.vsix下载 Microsoft Visual Studio Installer Projects (2022)

InstallerProjects.vsix 是微软官方提供的winform程序打包工具&#xff0c;但是国内下载安装有时候比较慢。虽然只有5m左右&#xff0c;但是国内就是下载不下来。现将官网地址和下载后的百度网盘共享地址展示如下&#xff1a;方便大家使用 官方地址&#xff1a;https://market…

[C++] string类常用接口的模拟实现

文章目录 1、前言2、遍历2.1 operator[ ]下标方式2.2 迭代器2.3 范围for2.4 c_str 3、容量相关3.1 size&#xff08;大小&#xff09;3.2 capacity&#xff08;容量&#xff09;3.3 empty&#xff08;判空&#xff09;3.4 clear&#xff08;清理&#xff09;3.5 reserve3.6 res…