You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2023/01/24 12:22:18 UTC
[tomcat] 02/02: LongAdder is a better choice for statistics collection
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
commit 2acb530d27f87ac30acc76f54cfa13fe3f21fa4e
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Jan 24 12:22:01 2023 +0000
LongAdder is a better choice for statistics collection
---
java/org/apache/catalina/webresources/Cache.java | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/java/org/apache/catalina/webresources/Cache.java b/java/org/apache/catalina/webresources/Cache.java
index 949117f521..4893a289cb 100644
--- a/java/org/apache/catalina/webresources/Cache.java
+++ b/java/org/apache/catalina/webresources/Cache.java
@@ -22,6 +22,7 @@ import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.LongAdder;
import org.apache.catalina.WebResource;
import org.apache.catalina.WebResourceRoot.CacheStrategy;
@@ -48,8 +49,8 @@ public class Cache {
private int objectMaxSize = (int) maxSize / OBJECT_MAX_SIZE_FACTOR;
private CacheStrategy cacheStrategy;
- private AtomicLong lookupCount = new AtomicLong(0);
- private AtomicLong hitCount = new AtomicLong(0);
+ private LongAdder lookupCount = new LongAdder();
+ private LongAdder hitCount = new LongAdder();
private final ConcurrentMap<String, CachedResource> resourceCache = new ConcurrentHashMap<>();
@@ -70,7 +71,7 @@ public class Cache {
}
}
- lookupCount.incrementAndGet();
+ lookupCount.increment();
CachedResource cacheEntry = resourceCache.get(path);
@@ -138,14 +139,14 @@ public class Cache {
cacheEntry.validateResource(useClassLoaderResources);
}
} else {
- hitCount.incrementAndGet();
+ hitCount.increment();
}
return cacheEntry;
}
protected WebResource[] getResources(String path, boolean useClassLoaderResources) {
- lookupCount.incrementAndGet();
+ lookupCount.increment();
// Don't call noCache(path) since the class loader only caches
// individual resources. Therefore, always cache collections here
@@ -196,7 +197,7 @@ public class Cache {
cacheEntry.validateResources(useClassLoaderResources);
}
} else {
- hitCount.incrementAndGet();
+ hitCount.increment();
}
return cacheEntry.getWebResources();
@@ -291,11 +292,11 @@ public class Cache {
}
public long getLookupCount() {
- return lookupCount.get();
+ return lookupCount.sum();
}
public long getHitCount() {
- return hitCount.get();
+ return hitCount.sum();
}
public void setObjectMaxSize(int objectMaxSize) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org