如何调整Tomcat的cacheMaxSize?

Tomcat

1 前言

一个问题,一篇文章,一出故事。
笔者通过以下命令查看Tomcat日志,

tail -f /usr/tomcat/apache-tomcat-8.5.81/logs/catalina.out

发现有如下大量重复出现的日志,日志范例如下,

22-Aug-2023 09:01:56.476 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.webresources.Cache.backgroundProcess The background cache eviction process was unable to free [10] percent of the cache for Context [/APPName] - consider increasing the maximum size of the cache. After eviction approximately [80,862] KB of data remained in the cache.

根据Tomcat的官方文档,有如下解析,

The maximum size of the static resource cache in kilobytes. If not specified, the default value is 10240 (10 megabytes). This value may be changed while the web application is running (e.g. via JMX). If the cache is using more memory than the new limit the cache will attempt to reduce in size over time to meet the new limit. If necessary, cacheObjectMaxSize will be reduced to ensure that it is no larger than cacheMaxSize/20.

注:以上大意是,警告缓存不够,默认值是10MB

2 最佳实践

2.1 修改配置

vim /usr/tomcat/apache-tomcat-8.5.81/conf/context.xml

修改如下配置,

<Context>
    #...
    <Resources cachingAllowed="true" cacheMaxSize="200000" />
    #...
</Context>

注:调整为200MB

2.2 重启服务使配置生效

systemctl restart tomcat
systemctl status tomcat

参阅文档
========================

https://tomcat.apache.org/tomcat-8.0-doc/config/resources.html

没有评论

发表回复

Tomcat
如何分析Tomcat的堆栈信息?

获取Tomcat的进程号 tomcatPid=`pgrep -u tomcat java` 如果遇到 …

Tomcat
如何配置Tomcat重写后跳转?

1 前言 一个问题,一篇文章,一出故事。 笔者遇到服务迁移需要使用Tomcat实现跳转,即实现用户访 …

Tomcat
如何基于RHEL 9.x部署TomCat之二?

1 前言 一个问题,一篇文章,一出故事。 笔者最近需要在生产环境安装部署Tomcat,于是重新整理T …