This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new ca9b39f0a1 Add debug logging for cache size
ca9b39f0a1 is described below

commit ca9b39f0a1e0086e9447d03a1c34d1528558a4b9
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Oct 30 10:50:40 2024 +0000

    Add debug logging for cache size
---
 java/org/apache/catalina/webresources/Cache.java       | 18 +++++++++++++++---
 .../catalina/webresources/LocalStrings.properties      |  2 ++
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/catalina/webresources/Cache.java 
b/java/org/apache/catalina/webresources/Cache.java
index 03e933d37c..ad41aaa983 100644
--- a/java/org/apache/catalina/webresources/Cache.java
+++ b/java/org/apache/catalina/webresources/Cache.java
@@ -99,7 +99,11 @@ public class Cache {
                 // there is still benefit in caching the resource metadata
 
                 long delta = cacheEntry.getSize();
-                size.addAndGet(delta);
+                long result = size.addAndGet(delta);
+                if (log.isDebugEnabled()) {
+                    log.debug(sm.getString("cache.sizeTracking.add", 
Long.toString(delta), cacheEntry, path,
+                            Long.toString(result)));
+                }
 
                 if (size.get() > maxSize) {
                     // Process resources unordered for speed. Trades cache
@@ -175,7 +179,11 @@ public class Cache {
 
                 // Content will not be cached but we still need metadata size
                 long delta = cacheEntry.getSize();
-                size.addAndGet(delta);
+                long result = size.addAndGet(delta);
+                if (log.isDebugEnabled()) {
+                    log.debug(sm.getString("cache.sizeTracking.add", 
Long.toString(delta), cacheEntry, path,
+                            Long.toString(result)));
+                }
 
                 if (size.get() > maxSize) {
                     // Process resources unordered for speed. Trades cache
@@ -261,7 +269,11 @@ public class Cache {
         CachedResource cachedResource = resourceCache.remove(path);
         if (cachedResource != null) {
             long delta = cachedResource.getSize();
-            size.addAndGet(-delta);
+            long result = size.addAndGet(-delta);
+            if (log.isDebugEnabled()) {
+                log.debug(sm.getString("cache.sizeTracking.remove", 
Long.toString(delta), cachedResource, path,
+                        Long.toString(result)));
+            }
         }
     }
 
diff --git a/java/org/apache/catalina/webresources/LocalStrings.properties 
b/java/org/apache/catalina/webresources/LocalStrings.properties
index 0b8472f238..c964d31291 100644
--- a/java/org/apache/catalina/webresources/LocalStrings.properties
+++ b/java/org/apache/catalina/webresources/LocalStrings.properties
@@ -26,6 +26,8 @@ cache.addFail=Unable to add the resource at [{0}] to the 
cache for web applicati
 cache.backgroundEvictFail=The background cache eviction process was unable to 
free [{0}] percent of the cache for Context [{1}] - consider increasing the 
maximum size of the cache. After eviction approximately [{2}] KiB of data 
remained in the cache.
 cache.objectMaxSizeTooBig=The value of [{0}] KiB for objectMaxSize is larger 
than the limit of maxSize/20 so has been reduced to [{1}] KiB
 cache.objectMaxSizeTooBigBytes=The value specified for the maximum object size 
to cache [{0}] KiB is greater than Integer.MAX_VALUE bytes which is the maximum 
size that can be cached. The limit will be set to Integer.MAX_VALUE bytes.
+cache.sizeTracking.add=Increased cache size by [{0}] for item [{1}] at [{2}] 
making total cache size [{3}]
+cache.sizeTracking.removed=Decreased cache size by [{0}] for item [{1}] at 
[{2}] making total cache size [{3}]
 
 cachedResource.invalidURL=Unable to create an instance of 
CachedResourceURLStreamHandler because the URL [{0}] is malformed
 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to