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

相关内容

热门资讯

Python|位运算|数组|动... 目录 1、只出现一次的数字(位运算,数组) 示例 选项代...
张岱的人物生平 张岱的人物生平张岱(414年-484年),字景山,吴郡吴县(今江苏苏州)人。南朝齐大臣。祖父张敞,东...
西游西后传演员女人物 西游西后传演员女人物西游西后传演员女人物 孙悟空 六小龄童 唐僧 徐少华 ...
名人故事中贾岛作诗内容简介 名人故事中贾岛作诗内容简介有一次,贾岛骑驴闯了官道.他正琢磨着一句诗,名叫《题李凝幽居》全诗如下:闲...
和男朋友一起优秀的文案? 和男朋友一起优秀的文案?1.希望是惟一所有的人都共同享有的好处;一无所有的人,仍拥有希望。2.生活,...
戴玉手镯的好处 戴玉手镯好还是... 戴玉手镯的好处 戴玉手镯好还是碧玺好 女人戴玉?戴玉好还是碧玺好点佩戴手镯,以和田玉手镯为佳!相嫌滑...
依然什么意思? 依然什么意思?依然(汉语词语)依然,汉语词汇。拼音:yī    rán基本解释:副词,指照往常、依旧...
高尔基的散文诗 高尔基的散文诗《海燕》、《大学》、《母亲》、《童年》这些都是比较出名的一些代表作。
心在飞扬作者简介 心在飞扬作者简介心在飞扬作者简介如下。根据相关公开资料查询,心在飞扬是一位优秀的小说作者,他的小说作...
卡什坦卡的故事赏析? 卡什坦卡的故事赏析?讲了一只小狗的故事, 我也是近来才读到这篇小说. 作家对动物的拟人描写真是惟妙...
林绍涛为简艾拿绿豆糕是哪一集 林绍涛为简艾拿绿豆糕是哪一集第三十二集。 贾宽认为是阎帅间接导致刘映霞住了院,第二天上班,他按捺不...
小爱同学是女生吗小安同学什么意... 小爱同学是女生吗小安同学什么意思 小爱同学,小安同学说你是女生。小安是男的。
内分泌失调导致脸上长斑,怎么调... 内分泌失调导致脸上长斑,怎么调理内分泌失调导致脸上长斑,怎么调理先调理内分泌,去看中医吧,另外用好的...
《魔幻仙境》刺客,骑士人物属性... 《魔幻仙境》刺客,骑士人物属性加点魔幻仙境骑士2功1体质
很喜欢她,该怎么办? 很喜欢她,该怎么办?太冷静了!! 太理智了!爱情是需要冲劲的~不要考虑着考虑那~否则缘...
言情小说作家 言情小说作家我比较喜欢匪我思存的,很虐,很悲,还有梅子黄时雨,笙离,叶萱,还有安宁的《温暖的玄》 小...
两个以名人的名字命名的风景名胜... 两个以名人的名字命名的风景名胜?快太白楼,李白。尚志公园,赵尚志。
幼儿教育的代表人物及其著作 幼儿教育的代表人物及其著作卡尔威特的《卡尔威特的教育》,小卡尔威特,他儿子成了天才后写的《小卡尔威特...
海贼王中为什么说路飞打凯多靠霸... 海贼王中为什么说路飞打凯多靠霸气升级?凯多是靠霸气升级吗?因为之前刚到时确实打不过人家因为路飞的实力...
运气不好拜财神有用吗运气不好拜... 运气不好拜财神有用吗运气不好拜财神有没有用1、运气不好拜财神有用。2、拜财神上香前先点蜡烛,照亮人神...