[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=17620413#comment-17620413 ] Jacques Le Roux commented on OFBIZ-6747: Finally, I has a serious look at UtilCache. I wrote above: bq. CLHM is only used in 2 places: UtilCache and ServiceDispatcher classes. Moreover in UtilCache it's only really used OOTB by EntityPerformanceTest.groovy. Actually last sentence is wrong. CLHM in UtilCache is OOTB only used by UtilCacheTests class. I traced it back. CLHM was put in UtilCache by Adam more than 10 years ago. I guess he used it on his side. It's not used OOTB apart that. And we have a problem with UtilCacheTests, because we can't cast Caffeine to a Map without using its asMap() method. So we get the errors below when running tests with OFBIZ-6747.patch applied, when all the rest is OK. {noformat} > Task :test org.apache.ofbiz.base.util.cache.UtilCacheTests > testCreateUtilCache FAILED java.lang.ClassCastException at UtilCacheTests.java:216 org.apache.ofbiz.base.util.cache.UtilCacheTests > testPutIfAbsent FAILED java.lang.ClassCastException at UtilCacheTests.java:184 org.apache.ofbiz.base.util.cache.UtilCacheTests > testPutIfAbsentAndGet FAILED java.lang.ClassCastException at UtilCacheTests.java:184 org.apache.ofbiz.base.util.cache.UtilCacheTests > testExpire FAILED java.lang.ClassCastException at UtilCacheTests.java:184 org.apache.ofbiz.base.util.cache.UtilCacheTests > testSimple FAILED java.lang.ClassCastException at UtilCacheTests.java:184 org.apache.ofbiz.base.util.cache.UtilCacheTests > testChangeMemSize FAILED java.lang.ClassCastException at UtilCacheTests.java:184 for UtilCacheTests to {noformat} Only for these specific cases we would need to create a UtilCacheAsMap class to set the inner memoryTable as a Map using asMap() method. Let's summarize the OOTB situation: because of maxInMemory parameter, UtilCache never uses CLHM (Caffeine in our case) but in UtilCacheTests Here are the options: # Using Caffeine, we create a specific UtilCacheAsMap class, only to satisfy UtilCacheTests # We remove both CLHM from UtilCache and UtilCacheTests # We let things as they are # is complicated for no OOTB gains, and I guess even for users (Adam no longer seems to worry about OFBiz) # is cleaner but needs some work and could annoy some old users migration # seems the best option to me Here is the patch [^OFBIZ-6747.patch] > 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 > > Attachments: OFBIZ-6747.patch > > > 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=17620078#comment-17620078 ] Jacques Le Roux commented on OFBIZ-6747: Forgot to mention that I fixed the EntityPerformanceTest.groovy error in log with OFBIZ-12706 > 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=17619430#comment-17619430 ] ASF subversion and git services commented on OFBIZ-6747: Commit 88dd89f4889e4c70db9ed7669a019fc378428a72 in ofbiz-framework's branch refs/heads/trunk from Jacques Le Roux [ https://gitbox.apache.org/repos/asf?p=ofbiz-framework.git;h=88dd89f488 ] Improved: Replace ConcurrentLinkedHashMap by Caffeine (OFBIZ-6747) Here only ServiceDispatcher is modified. Thanks: Ben Manes for suggestion and help > 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=17619429#comment-17619429 ] Jacques Le Roux commented on OFBIZ-6747: Thanks for the tip was useful in one case (getServiceLogMap). Else I simply used Cache class when creating. > 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=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] [Commented] (OFBIZ-6747) Replace ConcurrentLinkedHashMap by Caffeine
[ https://issues.apache.org/jira/browse/OFBIZ-6747?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=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=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(); + private static
[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=17616811#comment-17616811 ] ASF subversion and git services commented on OFBIZ-6747: Commit b2edffde857f572194055e80a785a911c1ca71de in ofbiz-framework's branch refs/heads/trunk from Jacques Le Roux [ https://gitbox.apache.org/repos/asf?p=ofbiz-framework.git;h=b2edffde85 ] Improved: Replace ConcurrentLinkedHashMap by Caffeine (OFBIZ-6747) This is a Java 8 rewrite based on changes in CLHM and Guava's cache. As expected it provides superior performance. It also provides a near optimal eviction policy. Thanks: Ben Manes for suggestion and advice > 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=17616809#comment-17616809 ] ASF subversion and git services commented on OFBIZ-6747: Commit bc38d2db178d139605cb039b1de904489c8dae0e in ofbiz-plugins's branch refs/heads/trunk from Jacques Le Roux [ https://gitbox.apache.org/repos/asf?p=ofbiz-plugins.git;h=bc38d2db1 ] Improved: Replace ConcurrentLinkedHashMap by Caffeine (OFBIZ-6747) This is a Java 8 rewrite based on changes in CLHM and Guava's cache. As expected it provides superior performance. It also provides a near optimal eviction policy. Thanks: Ben Manes for suggestion and advice > 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=17616231#comment-17616231 ] Jacques Le Roux commented on OFBIZ-6747: Indeed, just tried: 2 errors to fix, does not seem hard... later... > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task > Components: ALL COMPONENTS >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > 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=17616204#comment-17616204 ] Ben Manes commented on OFBIZ-6747: -- I see that comment in your {{ldap/build.gradle}} file, but now that you changed the "consumer" to 11 it should allow you to upgrade? > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task > Components: ALL COMPONENTS >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > 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=17616197#comment-17616197 ] Jacques Le Roux commented on OFBIZ-6747: We crossed on wire :) > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task > Components: ALL COMPONENTS >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > 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=17616196#comment-17616196 ] Jacques Le Roux commented on OFBIZ-6747: Thanks for targetCompatibility info. As I said I'm far from a Gradle specialist :/ So 3.1.1 compiles when using sourceCompatibility = '11' targetCompatibility = '11' Not even a problem with solr-core. We are already running all our branches with Java 11. Remains solr-core but that's another issue (with also our LDAP plugin that says: bq. pluginLibsCompile 'org.apereo.cas:cas-server-support-ldap-core:5.0.10' // 6.4.0 declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8) > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task > Components: ALL COMPONENTS >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > 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=17616194#comment-17616194 ] Ben Manes commented on OFBIZ-6747: -- I think you could change these [two lines|https://github.com/apache/ofbiz-framework/blob/ac2270118df04bc593d4af029942478f85f13f01/build.gradle#L125-L126] to 11 and it might work, {code:groovy} sourceCompatibility = '1.8' targetCompatibility = '1.8' {code} > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task > Components: ALL COMPONENTS >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > 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=17616193#comment-17616193 ] Jacques Le Roux commented on OFBIZ-6747: By curiosity I tried that with 3.1.1: {code} --- a/build.gradle +++ b/build.gradle @@ -100,7 +100,7 @@ javadoc { // Those external Javadoc links should correspond to the actual // versions declared in the 'dependencies' block. links( -'https://docs.oracle.com/javase/8/docs/api', +'https://docs.oracle.com/javase/11/docs/api', 'https://tomcat.apache.org/tomcat-9.0-doc/servletapi/', 'http://docs.groovy-lang.org/docs/groovy-2.5.18/html/api', 'https://commons.apache.org/proper/commons-cli/apidocs' {code} Excluding solr-core, I thought the problem could be using a reference to Java 8 API. But I get the same error. I don't clearly understand why it says: {code} The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally {code} I don't see any other place where Java 8 is required. I must say I'm not a Gradle specialist Anyway, more as an information for us. As we said we can still use CLHM. Anyway, that's not the sole dependency we are stuck with. OFBiz is a 21 years old large project, quite mature we can say ;) > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task > Components: ALL COMPONENTS >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > 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=17616191#comment-17616191 ] Ben Manes commented on OFBIZ-6747: -- {quote}We run under Java 11, but the build requires Java 8, right? {quote} Yes, in your build file it specifies {{{}targetCompatibility = '1.8'{}}}. Since Caffeine v3.x targets 11 it fails when Gradle inspects their module metadata rather that at compile / runtime due to an unsupported class file version. Unfortunately the error messages are not very clear and I even ran into a dependency's [mismatch|https://github.com/tbroyer/gradle-errorprone-plugin/issues/73] yesterday. The {{:}} is short for the root project, so a subproject would be {{:applications:workeffort}} (via {{{}gradlew projects{}}}). In your setup I think it is applied everywhere. {quote}Also we are somehow stuck with solr-core 8 {quote} fwiw, Solr 8.3 adopted Caffeine and removed their custom caches in 9.0. > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task > Components: ALL COMPONENTS >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > 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=17616188#comment-17616188 ] Jacques Le Roux commented on OFBIZ-6747: Hi Ben, I'm still not sure to understand the reason we need 2.9.3. We run under Java 11, but the build requires Java 8, right? Something I don't understand is the 1st block of error {quote} > Could not resolve com.github.ben-manes.caffeine:caffeine:3.1.1. Required by: project : > No matching variant of com.github.ben-manes.caffeine:caffeine:3.1.1 was found. {quote} "project" is empty. I guess it means the whole project (ie ofbiz), right? Also we are somehow stuck with solr-core 8 (OFBIZ-10633). {quote} So it works but I'm unsure of the situation. So I suggest for now to continue to use the 8 branch. {quote} Fortunately, as you said, we can live with CLHM for now, no hurry :) > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task > Components: ALL COMPONENTS >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > 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=17615993#comment-17615993 ] Ben Manes commented on OFBIZ-6747: -- Good catch. The error you saw and figured out is that Caffeine v3 requires Java 11+, but your build targets Java 8. {quote}The consumer was configured to find a runtime of a library compatible with Java 8 {quote} The minimum requirements change was to migrate from {{sun.misc.Unsafe}} to {{VarHandles}} (Java 9). The usage was primarily to avoid per-entry bloat of a few {{AtomicReference}} fields so benign, but understandably no one's preference. For Java 8 the only alternative is {{AtomicReferenceFieldUpdater,}} but that uses reflection per call so known that it can be slow. Anyway, the main motivation for this ticket was informing you of the dependency's evolution. As it works fine I don't want to create headaches, just awareness that CLHM is stable but end-of-life with the successor being Caffeine. It's perfectly fine to stay as is. > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task > Components: ALL COMPONENTS >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > 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=17615730#comment-17615730 ] Jacques Le Roux commented on OFBIZ-6747: 2.9.3 works > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task > Components: ALL COMPONENTS >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > 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=17615671#comment-17615671 ] Jacques Le Roux commented on OFBIZ-6747: I tried to add caffeine:3.1.1 and got this: {noformat} > Could not resolve com.github.ben-manes.caffeine:caffeine:3.1.1. Required by: project : > No matching variant of com.github.ben-manes.caffeine:caffeine:3.1.1 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally but: - Variant 'apiElements' capability com.github.ben-manes.caffeine:caffeine:3.1.1 declares a library, packaged as a jar, and its dependencies declared externally: - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8 - Variant 'javadocElements' capability com.github.ben-manes.caffeine:caffeine:3.1.1 declares a runtime of a component, and its dependencies declared externally: - Incompatible because this component declares documentation and the consumer needed a library - Other compatible attributes: - Doesn't say anything about its target Java version (required compatibility with Java 8) - Doesn't say anything about its elements (required them packaged as a jar) - Variant 'runtimeElements' capability com.github.ben-manes.caffeine:caffeine:3.1.1 declares a runtime of a library, packaged as a jar, and its dependencies declared externally: - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8 - Variant 'sourcesElements' capability com.github.ben-manes.caffeine:caffeine:3.1.1 declares a runtime of a component, and its dependencies declared externally: - Incompatible because this component declares documentation and the consumer needed a library - Other compatible attributes: - Doesn't say anything about its target Java version (required compatibility with Java 8) - Doesn't say anything about its elements (required them packaged as a jar) > Could not resolve com.github.ben-manes.caffeine:caffeine:2.9.2. Required by: project : > project :plugins:solr > org.apache.solr:solr-core:8.11.2 > No matching variant of com.github.ben-manes.caffeine:caffeine:3.1.1 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally but: - Variant 'apiElements' capability com.github.ben-manes.caffeine:caffeine:3.1.1 declares a library, packaged as a jar, and its dependencies declared externally: - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8 - Variant 'javadocElements' capability com.github.ben-manes.caffeine:caffeine:3.1.1 declares a runtime of a component, and its dependencies declared externally: - Incompatible because this component declares documentation and the consumer needed a library - Other compatible attributes: - Doesn't say anything about its target Java version (required compatibility with Java 8) - Doesn't say anything about its elements (required them packaged as a jar) - Variant 'runtimeElements' capability com.github.ben-manes.caffeine:caffeine:3.1.1 declares a runtime of a library, packaged as a jar, and its dependencies declared externally: - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8 - Variant 'sourcesElements' capability com.github.ben-manes.caffeine:caffeine:3.1.1 declares a runtime of a component, and its dependencies declared externally: - Incompatible because this component declares documentation and the consumer needed a library - Other compatible attributes: - Doesn't say anything about its target Java version (required compatibility with Java 8) - Doesn't say anything about its elements (required them packaged as a jar) {noformat} I tried to comment out related tasks. after 3 changes decided to stop. It seems similar to https://github.com/ben-manes/caffeine/issues/716 but I have not yet looked into details > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task > Components: ALL COMPONENTS >Reporter: Ben Manes >
[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=17615572#comment-17615572 ] Jacques Le Roux commented on OFBIZ-6747: Thanks Ben, That's another perspective to consider indeed! > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task > Components: ALL COMPONENTS >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > 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=17615508#comment-17615508 ] Ben Manes commented on OFBIZ-6747: -- Sorry, I did not mean for you to replace {{UtilCache}} as it provides a nice abstraction. The internal implementation could switch from CLHM to Caffeine. This would be less invasive as Caffeine offers all of the older library's functionality, with the caveat that the eviction policy differs (if sadly someone depended on LRU behavior). It may be that you could reduce code by migrating features like expiration and soft references to Caffeine, but that would be a larger, more complicated effort. > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task > Components: ALL COMPONENTS >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > 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=17615501#comment-17615501 ] Jacques Le Roux commented on OFBIZ-6747: This is not an easy work. There are 289 occurrences of UtilCache class usage in both Java and Groovy files. And the UtilCache and Caffeine APIs are of course different. It does not mean that we can't do it. But that's a huge and risky task... > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task > Components: ALL COMPONENTS >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > 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=16511657#comment-16511657 ] Jacques Le Roux commented on OFBIZ-6747: Hi Taher, actually I'm not working on this at the moment. If you feel like working on it please feel free to assign yourself :) > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > 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 (v7.6.3#76005)
[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=16510062#comment-16510062 ] Ben Manes commented on OFBIZ-6747: -- In regards to fun algorithms, some resources to look into are... * For general concurrency, the book [The Art of Multiprocessor Programming|https://www.amazon.com/Art-Multiprocessor-Programming-Revised-Reprint/dp/0123973376] is excellent. It covers lock-free algorithms and is written by researchers who authored many well known papers. * The concurrency scheme used by my caches is inspired by a database's write-ahead log. The classic approaches are to either thrash on a global lock to perform a tiny amount of work (usually pointer flipping) or avoid "movement" by using a CLOCK-based or random sampling policy. By instead recording into a ring buffer and replaying under a tryLock, the lock contention is replaced by a cheaper buffer CAS. This lets me uses non-threadsafe algorithms that are O(1) and more intelligent. The idea is simple and implementation just takes work to squeeze out performance. * For eviction, see the ACM paper on our policy. The pre-published is on the earlier link, while the peer reviewed version can be freely downloaded from the link on the README. I wrote an [overview|http://highscalability.com/blog/2016/1/25/design-of-a-modern-cache.html] ([slides|https://docs.google.com/presentation/d/1NlDxyXsUG1qlVHMl4vsUUBQfAJ2c2NsFPNPr2qymIBs/edit#slide=id.p]) for HighScalability. We have a followup paper under review that makes it adaptive. If interested, I can send that over private email due to submission restrictions (my email is on github). * For expiration, see this excellent article by the Kafka folks on [Hierarchical TimerWheel|https://www.confluent.io/blog/apache-kafka-purgatory-hierarchical-timing-wheels]. This is an amortized O(1) priority queue that leverages time to use hashing instead of tree-like comparisons. Caffeine is the only cache that I'm aware of to use this, but this data structure is fundamental in kernel subsystems. Its really elegant and fast! And the rest is all elbow grease! :) > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > Similar to OFBIZ-3779, please consider upgrading the library used by > [UtilCache|https://github.com/apache/ofbiz/blob/trunk/framework/base/src/org/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 (v7.6.3#76005)
[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=16510004#comment-16510004 ] Taher Alkhateeb commented on OFBIZ-6747: Ahh I just noticed that Jacques is working on this issue which I should've figured from the ML exchange, anyway I'll leave it to you to come up with a PoC then and we can discuss it here. > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > Similar to OFBIZ-3779, please consider upgrading the library used by > [UtilCache|https://github.com/apache/ofbiz/blob/trunk/framework/base/src/org/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 (v7.6.3#76005)
[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=16509486#comment-16509486 ] Taher Alkhateeb commented on OFBIZ-6747: Amazing Ben, in a few words you're opening my eyes to a whole bunch of ideas and I'm still reading on all the algorithms. Really fascinating stuff thank you for sharing. If you can also recommend any books that would be awesome. A problem we'll face is that our code base is rather old and pretty much spaghetti patterns are everywhere and most of our code is a concrete implementation without interfaces. I have to think of how to wire this Cache interface with the rest of the architecture cleanly. Perhaps one way is to to try and apply the ConcurrentMap signature on all methods, then create an adapter if / when needed with the UtilCache to keep everything working smoothly as we disentangle references to the Util class or others. Phew hurts my head just to say that :) > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > Similar to OFBIZ-3779, please consider upgrading the library used by > [UtilCache|https://github.com/apache/ofbiz/blob/trunk/framework/base/src/org/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 (v7.6.3#76005)
[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=16508752#comment-16508752 ] Ben Manes commented on OFBIZ-6747: -- If you do switch to Caffeine, a few minor notes to be aware of... # Modifying the maximum size at runtime is now at: {{Cache.policy().eviction().ifPresent(policy -> policy.setMaximum(newInMemory)}}. # Caffeine uses [W-TinyLFU|https://github.com/ben-manes/caffeine/wiki/Efficiency] instead of LRU, which incorporates frequency to provide a much higher hit-rate # The [overhead|https://github.com/ben-manes/caffeine/wiki/Benchmarks#read-100-1] of both caches, compared to an unbounded {{ConcurrentHashMap}} is probably not worth optimizing around. Caffeine performs at 33% read throughput and CLHM at 28%. In reality that's more than adequate since micro-benchmarks benefit from hardware cache efficiencies and don't include any application overhead. So in practice one does not observe a penalty given other work involved. Per your findings, I would think a custom {{Cache}} interface with your methods would be cleaner than {{instanceOf}} checks so as to encapsulate all of the implementation details of a provider. > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > Similar to OFBIZ-3779, please consider upgrading the library used by > [UtilCache|https://github.com/apache/ofbiz/blob/trunk/framework/base/src/org/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 (v7.6.3#76005)
[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=16508717#comment-16508717 ] Taher Alkhateeb commented on OFBIZ-6747: Thank you Ben, this is indeed quite informative. So I see two places where the specific implementation is used explicitly in the code: * org.apache.ofbiz.service.ServiceDispatcher: {code:java} protected static final Map runLog = new ConcurrentLinkedHashMap.Builder().maximumWeightedCapacity(lruLogSize).build(); {code} * org.apache.ofbiz.base.util.cache.UtilCache {code:java} public void setMaxInMemory(int newInMemory) { this.maxInMemory = newInMemory; Map> oldmap = this.memoryTable; if (newInMemory > 0) { if (this.memoryTable instanceof ConcurrentLinkedHashMap) { ((ConcurrentLinkedHashMap) this.memoryTable).setCapacity(newInMemory); return; } this.memoryTable =new Builder>() .maximumWeightedCapacity(newInMemory) .build(); } else { this.memoryTable = new ConcurrentHashMap<>(); } this.memoryTable.putAll(oldmap); } {code} So the question on my mind is, what is the simplest way to switch out. I guess we need to replace the builder logic along with the other specific methods that are being called. > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > Similar to OFBIZ-3779, please consider upgrading the library used by > [UtilCache|https://github.com/apache/ofbiz/blob/trunk/framework/base/src/org/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 (v7.6.3#76005)
[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=16507108#comment-16507108 ] Ben Manes commented on OFBIZ-6747: -- The two libraries do share a compatible interface via {{ConcurrentMap}}. That is the interface for {{ConcurrentLinkedHashMap}} and provided by Caffeine's {{Cache.asMap()}} view. You are welcome to abstract out caching as you see fit, as neither are invasive (e.g. no singleton {{CacheManager}} or configuration files - those are for applications to introduce and manage). {{ConcurrentLinkedHashMap}} was written for Java 5, so it does not provide atomic versions of the new default methods such as {{computeIfAbsent}}. I believe that the copy embedded by Groovy did add this, if you want to follow their example. The library is tiny, so many brought it under their own umbrella to avoid external dependencies (e.g. another example is SQL Server's JDBC driver). Unfortunately most other caching libraries do no support {{ConcurrentMap}}, so bridging them might be difficult. You may instead prefer to have a custom {{Cache}} interface with only the methods your project finds useful to minimize the effort. Another option is {{JSR107 JCache}} but be warned that it is riddled with problems, highly flawed, and results in a very frustrating developer experience. While the JSR was approved, it was rejected by JavaEE (both EE7 and EE8) and not widely adopted by consuming frameworks / applications. > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > Similar to OFBIZ-3779, please consider upgrading the library used by > [UtilCache|https://github.com/apache/ofbiz/blob/trunk/framework/base/src/org/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 (v7.6.3#76005)
[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=16506992#comment-16506992 ] Taher Alkhateeb commented on OFBIZ-6747: I am also in favor of Mathieu's approach. I assume the two libraries are not compatible in their APIs (hence the reason for the re-write) So I think it is better to redirect the effort towards moving the implementation to the pure standard JVM. I am going to study the code to see whether this is doable > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > Similar to OFBIZ-3779, please consider upgrading the library used by > [UtilCache|https://github.com/apache/ofbiz/blob/trunk/framework/base/src/org/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 (v7.6.3#76005)
[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=16506951#comment-16506951 ] Jacques Le Roux commented on OFBIZ-6747: Good point Mathieu, For history: [~doogie] was at the initiative: https://s.apache.org/b465 then OFBIZ-3779 For the rest I agree, it just needs an effort I don't want currently put into :) (other priorities, even in OFBiz) > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > Similar to OFBIZ-3779, please consider upgrading the library used by > [UtilCache|https://github.com/apache/ofbiz/blob/trunk/framework/base/src/org/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 (v7.6.3#76005)
[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=16506881#comment-16506881 ] Mathieu Lirzin commented on OFBIZ-6747: --- I am not aware about the whole story and the rationale behind it, but I think OFBiz shouldn't depend on non-standard libs like {{ConcurrentLinkedHashMap}} or {{Caffeine}}. The reason is that the framework should depend only the standard {{ConcurrentMap}} interface and should let users choose the implementation of their choice. To reduce the number of dependencies OFBiz should use one of the implementations from JavaSE by default and provide a way to plug those more performance focused implementations. A factory or any another configuration mechanism would make the job. > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > Similar to OFBIZ-3779, please consider upgrading the library used by > [UtilCache|https://github.com/apache/ofbiz/blob/trunk/framework/base/src/org/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 (v7.6.3#76005)
[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=16506858#comment-16506858 ] Jacques Le Roux commented on OFBIZ-6747: To clarify the issue, I changed the title from "Upgrade ConcurrentLinkedHashMap" to "Replace ConcurrentLinkedHashMap by Caffeine" > Replace ConcurrentLinkedHashMap by Caffeine > --- > > Key: OFBIZ-6747 > URL: https://issues.apache.org/jira/browse/OFBIZ-6747 > Project: OFBiz > Issue Type: Task >Reporter: Ben Manes >Assignee: Jacques Le Roux >Priority: Minor > > Similar to OFBIZ-3779, please consider upgrading the library used by > [UtilCache|https://github.com/apache/ofbiz/blob/trunk/framework/base/src/org/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 (v7.6.3#76005)