[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=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=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=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=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=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=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=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=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)