如何调整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的日志轮转?

1 前言 一个问题,一篇文章,一出故事。 笔者之前为Tomcat日志自动分割写过一个脚本,最近发现如 …

Tomcat
如何用JSSE配置Tomcat 9 HTTPS?

1 前言 一个问题,一篇文章,一出故事。 笔者需要在Tomcat生产环境启用Tomcat的HTTPS …

Tomcat
如何用OpenSSL SSL/TLS配置Tomcat 9 HTTPS?

1 前言 一个问题,一篇文章,一出故事。 笔者需要在Tomcat生产环境启用Tomcat的HTTPS …