【六祎 - Tomcat】Tomcat性能调优 - 参数;性能调优入门
创始人
2024-05-30 16:04:29
0

Tomcat性能调优 - 参数

    • tomcat版本号:8.5.82
      • StandardThreadExecutor 类
      • 配置修改

tomcat版本号:8.5.82

Tomcat的实现在org.apache.catalina.core.StandardThreadExecutor 里面的参数有

点这里→_→ 查看官方文档
在这里插入图片描述

  • maxThreads - Tomcat线程池最多能起的线程数
  • maxConnections - Tomcat最多能并发处理的请求(连接)
  • acceptCount - Tomcat维护最大的对列数
  • minSpareThreads - Tomcat初始化的线程池大小或者说Tomcat初始化线程池最少会有这么多线程。

maxThreads VS maxConnections 的区别

  • maxThreads是指Tomcat线程池最多能起的线程数
  • maxConnections则是Tomcat一瞬间做多能够处理的并发连接数

eg:
      比如maxThreads=1000,maxConnections=800,假设某一瞬间的并发时1000,那么最终Tomcat的线程数将会是800,即同时处理800个请求,剩余200进入队列“排队”,如果acceptCount=100,那么有100个请求会被拒掉。

StandardThreadExecutor 类

public class StandardThreadExecutor extends LifecycleMBeanBaseimplements Executor, ResizableExecutor {protected static final StringManager sm = StringManager.getManager(StandardThreadExecutor.class);// ---------------------------------------------- Properties/*** Default thread priority* 默认线程的优先级*/protected int threadPriority = Thread.NORM_PRIORITY;/*** Run threads in daemon or non-daemon state* 守护线程*/protected boolean daemon = true;/*** Default name prefix for the thread name* 线程名称的前缀*/protected String namePrefix = "tomcat-exec-";/*** max number of threads* 最大线程数默认200个*/protected int maxThreads = 200;/*** min number of threads* 最小空闲线程25个*/protected int minSpareThreads = 25;/*** idle time in milliseconds* 超时时间为6000毫秒*/protected int maxIdleTime = 60000;/*** The executor we use for this component* 线程池容器*/protected ThreadPoolExecutor executor = null;/*** the name of this thread pool* 线程池名称*/protected String name;/*** The maximum number of elements that can queue up before we reject them* 队列最大限度值*/protected int maxQueueSize = Integer.MAX_VALUE;/*** After a context is stopped, threads in the pool are renewed. To avoid* renewing all threads at the same time, this delay is observed between 2* threads being renewed.* 为了避免在上下文停止之后,所有的线程在同一时间段被更新,所以进行线程的延迟操作*/protected long threadRenewalDelay =org.apache.tomcat.util.threads.Constants.DEFAULT_THREAD_RENEWAL_DELAY;//任务队列private TaskQueue taskqueue = null;// ---------------------------------------------- Constructorspublic StandardThreadExecutor() {//empty constructor for the digester}// ---------------------------------------------- Public Methods/*** Start the component and implement the requirements* of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.** @exception LifecycleException if this component detects a fatal error*  that prevents this component from being used*/@Overrideprotected void startInternal() throws LifecycleException {//1.实例化任务队列taskqueue = new TaskQueue(maxQueueSize);//自定义的线程池工厂类,实现了JDK的ThreadFactory接口TaskThreadFactory tf = new TaskThreadFactory(namePrefix,daemon,getThreadPriority());//这里的ThreadPoolExecutor是tomcat自定义的(并非是JDK所属的)executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), maxIdleTime, TimeUnit.MILLISECONDS,taskqueue, tf);executor.setThreadRenewalDelay(threadRenewalDelay);//设置任务容器的父级线程池对象taskqueue.setParent(executor);//设置容器启动状态setState(LifecycleState.STARTING);}/*** 停止容器时的生命周期方法,关闭线程池和资源清理* Stop the component and implement the requirements* of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.** @exception LifecycleException if this component detects a fatal error*  that needs to be reported*/@Overrideprotected void stopInternal() throws LifecycleException {setState(LifecycleState.STOPPING);if (executor != null) {executor.shutdownNow();}executor = null;taskqueue = null;}/*** 这个执行线程方法有超时操作,参考 org.apache.catalina.Executor 接口* @param command the runnable task* @param timeout the length of time to wait for the task to complete* @param unit    the units in which timeout is expressed**/@Override@Deprecatedpublic void execute(Runnable command, long timeout, TimeUnit unit) {if (executor != null) {executor.execute(command,timeout,unit);} else {throw new IllegalStateException(sm.getString("standardThreadExecutor.notStarted"));}}/*** JDK默认操作线程的方法,参考java.util.concurrent.Executor 接口* @param command the runnable task*/@Overridepublic void execute(Runnable command) {if (executor != null) {// Note any RejectedExecutionException due to the use of TaskQueue// will be handled by the o.a.t.u.threads.ThreadPoolExecutorexecutor.execute(command);} else {throw new IllegalStateException(sm.getString("standardThreadExecutor.notStarted"));}}... ... .../*** 由于继承了 org.apache.tomcat.util.thread.ResizableExecutor 接口,所以可以重新定义线程池大小* @param corePoolSize 核心线程池大小* @param maximumPoolSize 最大核心线程池大小* @return*/@Overridepublic boolean resizePool(int corePoolSize, int maximumPoolSize) {if (executor == null) {return false;}executor.setCorePoolSize(corePoolSize);executor.setMaximumPoolSize(maximumPoolSize);return true;}
}

配置修改

  
  

  • 引用github
    • tomcat调优

相关内容

热门资讯

今年以来险企已举牌十三次 转自:中国银行保险报网□本报记者 朱艳霞近日,中邮保险通过协议转让方式受让东航物流7942.01万股...
第二十届“光博会”本周武汉开幕...     编者按    第20届“光博会”如约而至,光谷、武汉、湖北,本周将再次成为全球光电子信息产业...
【深化“三抓三促”行动 群众有... 【深化“三抓三促”行动 群众有话说】“气象服务让我们产出好茶”  新甘肃·甘肃日报记者 海晓宁  近...
安徽省本周气温或飙至38℃   连日来,全国天气舞台热闹非凡,暴雨、强对流、沙尘暴……气温的起伏和降水的动态都备受关注。5月11...
【强信心 看发展 招商引资拼落... 【强信心 看发展 招商引资拼落地】满满诚意带来“双向奔赴”——广药白云山项目落地陇西见闻  新甘肃·...
沙特阿美:一季度全球贸易格局变... 当地时间5月11日,沙特阿拉伯国家石油公司公布的2025年第一季度财报显示,受全球经济不确定性和油价...
天赐沃土育金谷:武安小米的产业... 中原新闻网邯郸讯(智振华)武安市地处河北省南部、太行山东麓,位于晋冀豫三省交界地带,总面积1806平...
今日12时起执行新规,长江干线... 据长江海事局,《长江干线安徽至四川段船舶航行规则》和配套的《长江干线安徽至四川段通航分道、推荐航路、...
北交所举行“四海扬帆”主题业绩... 转自:中国证券报  5月9日,北交所以“四海扬帆”为主题,精选一诺威、海泰新能、力佳科技、拾比佰以及...
校园里的科技嘉年华 转自:河北新闻网5月9日,秦皇岛市海港区在水一方小学学生观看机器狗表演。当日秦皇岛市海港区在水一方小...
洛阳客家联合会客家文化研究院成...   11日,洛阳客家联合会客家文化研究院成立。  洛阳客家联合会客家文化研究院(简称洛阳客家文化研究...
大厂各显神通 AI人才争夺战打... 转自:中国证券报新华财经北京5月12日电(记者 罗京)在近日举行的第六届上海创新创业青年50人论坛上...
网速更快 费用不变 你用上“5... 最近几天,越来越多用户发现自己手机屏幕上信号栏的图标已经从“5G”悄然变成了“5G-A”。什么是“5...
新亚电缆:机器人电缆研发阶段,... 投资者提问:请问贵公司有应用于外骨骼机器人的产品吗?董秘回答(新亚电缆SZ001382):公司的主要...
房产销售出售公民个人信息被罚 【#房产销售出售公民个人信息被罚#】面对群众频繁接到各类骚扰电话准确说出姓名、户型等信息进行定点推销...
受全球经济不确定性冲击 沙特阿... 当地时间11日,沙特阿拉伯国家石油公司公布的2025年第一季度财报显示,受全球经济不确定性和油价波动...
三星据悉与主要客户就提高DRA... 转自:财联社【三星据悉与主要客户就提高DRAM售价达成一致】财联社5月12日电,三星电子据悉本月初与...
价格降了!榴莲大量上市 一整个... 转自:央视网  眼下,来自东南亚地区的榴莲、山竹、椰子等热带水果进入了销售旺季。这两天,记者在广西南...
阿维塔12风洞测试成绩出炉!官... 近日,阿维塔官方针对旗下车型阿维塔12风阻系数一事进行了直播解读。阿维塔12在中国汽研的风洞实验室中...
进一步释放数字经济发展潜能 转自:中工网原标题:进一步释放数字经济发展潜能近日,国家发展改革委、国家数据局印发《2025年数字经...