聊聊tomcat的connection-timeout

本文主要研究一下tomcat的connection-timeout

ServerProperties.Tomcat

org/springframework/boot/autoconfigure/web/ServerProperties.java

	public static class Tomcat {/*** Access log configuration.*/private final Accesslog accesslog = new Accesslog();/*** Thread related configuration.*/private final Threads threads = new Threads();/*** Tomcat base directory. If not specified, a temporary directory is used.*/private File basedir;/*** Delay between the invocation of backgroundProcess methods. If a duration suffix* is not specified, seconds will be used.*/@DurationUnit(ChronoUnit.SECONDS)private Duration backgroundProcessorDelay = Duration.ofSeconds(10);/*** Maximum size of the form content in any HTTP post request.*/private DataSize maxHttpFormPostSize = DataSize.ofMegabytes(2);/*** Maximum amount of request body to swallow.*/private DataSize maxSwallowSize = DataSize.ofMegabytes(2);/*** Whether requests to the context root should be redirected by appending a / to* the path. When using SSL terminated at a proxy, this property should be set to* false.*/private Boolean redirectContextRoot = true;/*** Whether HTTP 1.1 and later location headers generated by a call to sendRedirect* will use relative or absolute redirects.*/private boolean useRelativeRedirects;/*** Character encoding to use to decode the URI.*/private Charset uriEncoding = StandardCharsets.UTF_8;/*** 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.*/private int maxConnections = 8192;/*** Maximum queue length for incoming connection requests when all possible request* processing threads are in use.*/private int acceptCount = 100;/*** Maximum number of idle processors that will be retained in the cache and reused* with a subsequent request. When set to -1 the cache will be unlimited with a* theoretical maximum size equal to the maximum number of connections.*/private int processorCache = 200;/*** Comma-separated list of additional patterns that match jars to ignore for TLD* scanning. The special '?' and '*' characters can be used in the pattern to* match one and only one character and zero or more characters respectively.*/private List<String> additionalTldSkipPatterns = new ArrayList<>();/*** Comma-separated list of additional unencoded characters that should be allowed* in URI paths. Only "< > [ \ ] ^ ` { | }" are allowed.*/private List<Character> relaxedPathChars = new ArrayList<>();/*** Comma-separated list of additional unencoded characters that should be allowed* in URI query strings. Only "< > [ \ ] ^ ` { | }" are allowed.*/private List<Character> relaxedQueryChars = new ArrayList<>();/*** Amount of time the connector will wait, after accepting a connection, for the* request URI line to be presented.*/private Duration connectionTimeout;/*** Static resource configuration.*/private final Resource resource = new Resource();/*** Modeler MBean Registry configuration.*/private final Mbeanregistry mbeanregistry = new Mbeanregistry();/*** Remote Ip Valve configuration.*/private final Remoteip remoteip = new Remoteip();//......}	

springboot的ServerProperties.Tomcat定义了connectionTimeout属性,用于指定接受连接之后等待uri的时间

customizeConnectionTimeout

org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java

	private void customizeConnectionTimeout(ConfigurableTomcatWebServerFactory factory, Duration connectionTimeout) {factory.addConnectorCustomizers((connector) -> {ProtocolHandler handler = connector.getProtocolHandler();if (handler instanceof AbstractProtocol) {AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;protocol.setConnectionTimeout((int) connectionTimeout.toMillis());}});}

customizeConnectionTimeout将connectionTimeout写入到AbstractProtocol

AbstractProtocol

org/apache/coyote/AbstractProtocol.java

    public void setConnectionTimeout(int timeout) {endpoint.setConnectionTimeout(timeout);}

AbstractProtocol将timeout设置到endpoint

AbstractEndpoint

org/apache/tomcat/util/net/AbstractEndpoint.java

	public void setConnectionTimeout(int soTimeout) { socketProperties.setSoTimeout(soTimeout); }/*** Keepalive timeout, if not set the soTimeout is used.*/private Integer keepAliveTimeout = null;public int getKeepAliveTimeout() {if (keepAliveTimeout == null) {return getConnectionTimeout();} else {return keepAliveTimeout.intValue();}}

AbstractEndpoint将timeout设置到socketProperties的soTimeout,另外它的getKeepAliveTimeout方法在keepAliveTimeout为null的时候,使用的是getConnectionTimeout

Http11Processor

org/apache/coyote/http11/Http11Processor.java

    public SocketState service(SocketWrapperBase<?> socketWrapper)throws IOException {RequestInfo rp = request.getRequestProcessor();rp.setStage(org.apache.coyote.Constants.STAGE_PARSE);// Setting up the I/OsetSocketWrapper(socketWrapper);// FlagskeepAlive = true;openSocket = false;readComplete = true;boolean keptAlive = false;SendfileState sendfileState = SendfileState.DONE;while (!getErrorState().isError() && keepAlive && !isAsync() && upgradeToken == null &&sendfileState == SendfileState.DONE && !protocol.isPaused()) {// Parsing the request headertry {if (!inputBuffer.parseRequestLine(keptAlive, protocol.getConnectionTimeout(),protocol.getKeepAliveTimeout())) {if (inputBuffer.getParsingRequestLinePhase() == -1) {return SocketState.UPGRADING;} else if (handleIncompleteRequestLineRead()) {break;}}//......}//......}//......}          

Http11Processor的service方法在执行inputBuffer.parseRequestLine时传入了keptAlive、protocol.getConnectionTimeout()、protocol.getKeepAliveTimeout()参数

小结

springboot提供了tomcat的connection-timeout参数配置,其配置的是socket timeout,不过springboot没有提供对keepAliveTimeout的配置,它默认是null,读取的是connection timeout的配置。

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

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

相关文章

github批量仓库克隆,git clone某个用户的所有仓库

利用github的api工具&#xff0c; 首先拿到用户名为kevin的所有仓库的url&#xff1a; curl "https://api.github.com/users/kevin/repos?per_page100&&page1" | grep -w clone_url >clone.txt过滤一下&#xff1a; grep -o https://[^"]* clone…

DM8单点_闪回查询报错flashback version has been out of date

问题描述 误操作后&#xff0c;闪回查询到某一时间点提示:“[-9801]:flashback version has been out of date.” SQL> SELECT * FROM PERSON_TYPE WHEN TIMESTAMP 2023-11-23 18:51:41; SELECT * FROM PERSON_TYPE WHEN TIMESTAMP 2023-11-23 18:51:41; [-9801]:flashbac…

redis运维(十九)redis 的扩展应用 lua(一)

一 redis 的扩展应用 lua redis如何保证原子操作 说明&#xff1a;引入lua脚本,核心解决原子性问题 ① redis为什么引入lua? lua脚本本身体积小,启动速度快 ② redis引入lua的优势 小结&#xff1a; 类似自定义redis命令 ③ redis中如何使用lua ④ EVAL 说明&#…

性能测试的指南:测试类型、性能测试步骤、最佳实践等!

近期公司为了节省成本搞了一波机房迁移&#xff0c;整合了一些南美部署架构。有一些上google云和有些下阿里云等大的调整。 在做机房迁移项目当中就需要思考如何进行性能测试&#xff0c;这种大的机房迁移SRE&#xff08;运维&#xff09;会针对组件会做一些单组件的性能测试&a…

【深度学习】参数优化和训练技巧

寻找合适的学习率(learning rate) 学习率是一个非常非常重要的超参数&#xff0c;这个参数呢&#xff0c;面对不同规模、不同batch-size、不同优化方式、不同数据集&#xff0c;其最合适的值都是不确定的&#xff0c;我们无法光凭经验来准确地确定lr的值&#xff0c;我们唯一可…

6.2.SDP协议

那今天呢&#xff1f;我们来介绍一下sdp协议&#xff0c;那实际上呢&#xff1f;sdp协议非常的简单。我们如果拿到一个stp的文档去看的话&#xff0c;那你要分阅里边的所有的内容会觉得很枯燥&#xff0c;但实际上呢&#xff0c;如果我们按照这张图所展示的结构去看stp的话。你…

Javascript每天一道算法题(十四)——合并数组区间_中等

文章目录 1、问题2、示例3、解决方法&#xff08;0&#xff09;方法0——双指针&#xff08;错误思路&#xff09;&#xff08;1&#xff09;方法1——双指针&#xff08;正确&#xff09; 总结 1、问题 以数组 intervals 表示若干个区间的集合&#xff0c;其中单个区间为 inte…

怎么读一个网络的代码

1.网络代码怎么来的&#xff1f; 我想要实现一个功能&#xff0c;这个功能是输入一张图像&#xff0c;返回一个类别结果。 所以很明确就有三个部分&#xff0c;一个是接受图像输入&#xff0c;一个是处理图像得到处理结果&#xff0c;一个是对处理结果判断生成结果。 现在想要使…

rocketmq 发送时异常:system busy 和 broker busy 解决方案

之前写的解决方案,都是基于测试环境测试的.到生产环境之后,正常使用没有问题,生产环境压测时,又出现了system busy异常(简直崩溃).最后在rocketmq群里大佬指导下,终于解决(希望是彻底解决). 下面直接给出结果: 目前通过生产环境各种参数修改测试得出: broker busy异常: 可通…

Using PeopleCode in Application Engine Programs在应用引擎程序中使用PeopleCode

This section provides an overview of PeopleCode and Application Engine programs and discusses how to: 本节概述了PeopleCode和应用程序引擎程序&#xff0c;并讨论了如何: Decide when to use PeopleCode.决定何时使用PeopleCode。Consider the program environment.考…

Java之《ATM自动取款机》(面向对象)

《JAVA编程基础》项目说明 一、项目名称&#xff1a; 基于JAVA控制台版本银行自动取款机 项目要求&#xff1a; 实现银行自动取款机的以下基本操作功能&#xff1a;读卡、取款、查询。&#xff08;自动取款机中转账、修改密码不作要求&#xff09; 具体要求&#xff1a; 读卡…

基于SSM的校园奶茶点单管理系统

基于SSM的校园奶茶点单管理系统的设计与实现~ 开发语言&#xff1a;Java数据库&#xff1a;MySQL技术&#xff1a;SpringMyBatisSpringMVC工具&#xff1a;IDEA/Ecilpse、Navicat、Maven 系统展示 主页 奶茶列表 登录界面 管理员界面 用户界面 摘要 随着社会的发展和科技的进…

ubuntu搭建phpmyadmin+wordpress

Ubuntu搭建phpmyadmin wordpress Linux系统设置&#xff1a;Ubuntu 22配置apache2搭建phpmyadmin配置Nginx环境&#xff0c;搭建wordpress Linux系统设置&#xff1a;Ubuntu 22 配置apache2 安装apache2 sudo apt -y install apache2设置端口号为8080 sudo vim /etc/apache…

paddle detection 训练参数

#####################################基础配置##################################### # 检测算法使用YOLOv3,backbone使用MobileNet_v1,数据集使用roadsign_voc的配置文件模板,本配置文件默认使用单卡,单卡的batch_size=1 # 检测模型的名称 architecture: YOLOv3 # 根据…

【CCF-PTA】第03届Scratch第05题 -- 统计出现次数最多的字

统计出现次数最多的字 【题目描述】 我国自古流传下来不少脍炙人口的诗歌&#xff0c;各具特色&#xff0c;别具一格。有些诗只用寥寥几个字&#xff0c;就能描绘出生动的意境。 请找出以下诗篇中出现次数最多的字&#xff0c;如果有多个字出现次数相同&#xff0c;则答案为…

Java中基于SSM框架的数据保存方法与日期处理

​ 一、详解 在SSM框架中&#xff0c;保存数据通常涉及到服务层和数据访问层。服务层处理业务逻辑&#xff0c;而数据访问层负责与数据库进行交互。 二、代码 Override public void save(Student student) { Date date new Date(); SimpleDateFormat format new Sim…

什么是LLC电路?

LLC电路是由2个电感和1个电容构成的谐振电路&#xff0c;故称之为LLC&#xff1b; LLC电路主要由三个元件组成&#xff1a;两个电感分别为变压器一次侧漏感(Lr)和励磁电感(Lm)&#xff0c;电容为变压器一次侧谐振电容(Cr)。这些元件构成了一个谐振回路&#xff0c;其中输入电感…

【C/PTA】函数专项练习(四)

本文结合PTA专项练习带领读者掌握函数&#xff0c;刷题为主注释为辅&#xff0c;在代码中理解思路&#xff0c;其它不做过多叙述。 目录 6-1 计算A[n]1/(1 A[n-1])6-2 递归实现顺序输出整数6-3 自然数的位数(递归版)6-4 分治法求解金块问题6-5 汉诺塔6-6 重复显示字符(递归版)…

字母异位词分组

给你一个字符串数组&#xff0c;请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。 字母异位词 是由重新排列源单词的所有字母得到的一个新单词。 示例 1: 输入: strs [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”] 输出: [[“bat”],[“nat”,“tan…

Android MemoryFile 共享内存

应用场景&#xff1a; 跨进程传输大数据&#xff0c;如文件、图片等&#xff1b; 技术选型&#xff1a; 共享内存–MemoryFile&#xff1b; 优点&#xff1a; 1. 共享内存没有传输大小限制&#xff0c;所以和应用总的分配内存一样&#xff08;512MB&#xff09;&#xff1…