[jira] [Commented] (OFBIZ-6747) Replace ConcurrentLinkedHashMap by Caffeine
[ https://issues.apache.org/jira/browse/OFBIZ-6747?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17619048#comment-17619048 ] Ben Manes commented on OFBIZ-6747: -- I think you want to use {{Cache.asMap()}} to get a map view. > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Improvement > Components: framework/base, framework/service >Affects Versions: Upcoming Branch >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > Fix For: Upcoming Branch > > > Similar to OFBIZ-3779, please consider upgrading the library used by > [UtilCache|https://github.com/apache/ofbiz/blob/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/cache/UtilCache.java] > (v1.2). The current version is 1.4.2 and is the last major release planned. > The preferable alternative would be to upgrade to > [Caffeine|https://github.com/ben-manes/caffeine]. This is a Java 8 rewrite > based on what I've learned since developing CLHM and Guava's cache. As > expected it provides [superior > performance|https://github.com/ben-manes/caffeine/wiki/Benchmarks]. It also > provides a [near > optimal|https://github.com/ben-manes/caffeine/wiki/Efficiency] eviction > policy. -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Comment Edited] (OFBIZ-6747) Replace ConcurrentLinkedHashMap by Caffeine
[ https://issues.apache.org/jira/browse/OFBIZ-6747?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17618986#comment-17618986 ] Jacques Le Roux edited comment on OFBIZ-6747 at 10/17/22 4:14 PM: -- Forgot to say that it's only the OOTB situation. Things can be changed using cache.properties. But that has no impact on UtilCache. was (Author: jacques.le.roux): Forgot to say that it's ony the OOTB situation. Things can be changed using cache.properties > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Improvement > Components: framework/base, framework/service >Affects Versions: Upcoming Branch >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > Fix For: Upcoming Branch > > > Similar to OFBIZ-3779, please consider upgrading the library used by > [UtilCache|https://github.com/apache/ofbiz/blob/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/cache/UtilCache.java] > (v1.2). The current version is 1.4.2 and is the last major release planned. > The preferable alternative would be to upgrade to > [Caffeine|https://github.com/ben-manes/caffeine]. This is a Java 8 rewrite > based on what I've learned since developing CLHM and Guava's cache. As > expected it provides [superior > performance|https://github.com/ben-manes/caffeine/wiki/Benchmarks]. It also > provides a [near > optimal|https://github.com/ben-manes/caffeine/wiki/Efficiency] eviction > policy. -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (OFBIZ-6747) Replace ConcurrentLinkedHashMap by Caffeine
[ https://issues.apache.org/jira/browse/OFBIZ-6747?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17618986#comment-17618986 ] Jacques Le Roux commented on OFBIZ-6747: Forgot to say that it's ony the OOTB situation. Things can be changed using cache.properties > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Improvement > Components: framework/base, framework/service >Affects Versions: Upcoming Branch >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > Fix For: Upcoming Branch > > > Similar to OFBIZ-3779, please consider upgrading the library used by > [UtilCache|https://github.com/apache/ofbiz/blob/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/cache/UtilCache.java] > (v1.2). The current version is 1.4.2 and is the last major release planned. > The preferable alternative would be to upgrade to > [Caffeine|https://github.com/ben-manes/caffeine]. This is a Java 8 rewrite > based on what I've learned since developing CLHM and Guava's cache. As > expected it provides [superior > performance|https://github.com/ben-manes/caffeine/wiki/Benchmarks]. It also > provides a [near > optimal|https://github.com/ben-manes/caffeine/wiki/Efficiency] eviction > policy. -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (OFBIZ-6747) Replace ConcurrentLinkedHashMap by Caffeine
[ https://issues.apache.org/jira/browse/OFBIZ-6747?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17618985#comment-17618985 ] Jacques Le Roux commented on OFBIZ-6747: Hi, As those interested certainly noticed the commits above are only somehow related to Caffeine. Actually to run Caffeine 3.1.1 Java 11 is needed. We are already running all current supported branches (including deprecated R18.12) with Java 11 for few months. But the main build. gradle was not clearly building with it. So that what those commits were all about. I tried to get further and so replace CLHM with Caffeine. As Taher mentionned above CLHM is only used in 2 places: UtilCache and ServiceDispatcher classes. Moreover in UtilCache it's only really used OOTB by EntityPerformanceTest.groovy. It's accessible in Webtools, eg: https://demo-trunk.ofbiz.apache.org/webtools/control/EntityPerformanceTest and is currently failing: {noformat} 2022-10-17 15:32:15,403 |27.0.0.1-8009-exec-1 |UtilCache |W| Error getting maxSize value from ResourceBundle for propNames: [null] java.lang.NullPointerException: null at org.apache.ofbiz.base.util.cache.UtilCache.getPropertyParam(UtilCache.java:155) ~[main/:?] at org.apache.ofbiz.base.util.cache.UtilCache.setPropertiesParams(UtilCache.java:181) ~[main/:?] at org.apache.ofbiz.base.util.cache.UtilCache.setPropertiesParams(UtilCache.java:174) ~[main/:?] at org.apache.ofbiz.base.util.cache.UtilCache.setPropertiesParams(UtilCache.java:170) ~[main/:?] at org.apache.ofbiz.base.util.cache.UtilCache.(UtilCache.java:126) ~[main/:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?] at java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[?:?] at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:80) ~[groovy-2.5.18.jar:2.5.18] at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:74) ~[groovy-2.5.18.jar:2.5.18] at org.codehaus.groovy.runtime.callsite.ConstructorSite.callConstructor(ConstructorSite.java:45) ~[groovy-2.5.18.jar:2.5.18] at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59) ~[groovy-2.5.18.jar:2.5.18] at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:237) ~[groovy-2.5.18.jar:2.5.18] at EntityPerformanceTest.run(EntityPerformanceTest.groovy:193) ~[?:?] {noformat} I did not dig into it, I guess it's a long time it's like that. All other usages of UtilCache simply use ConcurrentHashMap because maxInMemory is passed to 0. Now there is an important use of CLHM in ServiceDispatcher. There I tried Caffeine but got an issue I don't clearly understand. Here is my try: {code:java} .../org/apache/ofbiz/service/ServiceDispatcher.java | 19 ++- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java b/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java index dd85ece5fd..b9f2821490 100644 --- a/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java +++ b/framework/service/src/main/java/org/apache/ofbiz/service/ServiceDispatcher.java @@ -58,11 +58,13 @@ import org.apache.ofbiz.service.job.JobManager; import org.apache.ofbiz.service.job.JobManagerException; import org.apache.ofbiz.service.semaphore.ServiceSemaphore; -import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap; +//import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap; +import com.github.benmanes.caffeine.cache.Caffeine; + + /** - * The global service dispatcher. This is the "engine" part of the - * Service Engine. + * The global service dispatcher. This is the "engine" part of the Service Engine. */ public final class ServiceDispatcher { @@ -70,8 +72,15 @@ public final class ServiceDispatcher { public static final int LRU_LOG_SIZE = 200; public static final int LOCK_RETRIES = 3; -private static final Map RUN_LOG = new ConcurrentLinkedHashMap.Builder().maximumWeightedCapacity(LRU_LOG_SIZE).build(); +//private static final Map RUN_LOG = new ConcurrentLinkedHashMap.Builder().maximumWeightedCapacity(LRU_LOG_SIZE).build(); + +@SuppressWarnings("unchecked") +private static final Map RUN_LOG = (Map) Caffeine.newBuilder() +.maximumSize(LRU_LOG_SIZE) +//.executor(Runnable::run) +.build(); + priv