【六祎 - 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调优

相关内容

热门资讯

玉皇阁大桥施工通告   玉皇阁大桥桥面铺装存在多处车辙、拥包、裂缝等病害,影响车辆通行,存在安全隐患。为确保车辆安全行驶...
前5个月软件业利润总额同比增长... 工业和信息化部最新发布的数据显示,今年前5个月,我国软件和信息技术服务业(下简称“软件业”)运行态势...
民机材料产量同比激增170%   东轻公司中厚板生产线。  本报讯(高琳 记者 梁可心)记者从东北轻合金有限责任公司了解到,今年上...
【提示公告】关于警惕假借东北证... (转自:东北证券金融世界)尊敬的投资者:您好!近期,有不法分子假冒东北证券(以下简称“我公司”)工作...
商业航天驶入发展快车道 相关概... 转自:证券日报7月2日,据报道,由中科宇航技术股份有限公司(以下简称“中科宇航”)研发的“力箭二号”...
罗马仕深夜回应倒闭传闻 7月3日晚,深圳罗马仕科技有限公司官方微博发文回应“倒闭”传闻:没有倒闭,感谢关心。定将努力解决所有...
世俱杯赛前诸葛亮 | 帕尔梅... 转自:扬子晚报周五002 弗鲁米嫩塞VS利雅得新月竞彩胜平负固定奖金:2.70、3.00、2.35竞...
国新办举行新闻发布会介绍抗战胜... 转自:贵州日报 新华社北京7月3日电 国务院新闻办公室3日举行新闻发布会,介绍中国人民抗日战...
沙特启用“萨德”反导部队 转自:湖州日报  新华社利雅得7月3日电(记者  罗晨  王海洲)沙特阿拉伯国防部2日发表声明说,沙...
宗申动力主业发力半年预盈4.8... 长江商报消息 ●长江商报记者 沈右荣“通用机械”和“摩托车发动机”两大传统主业共同发力,宗申动力(0...