[ 
https://issues.apache.org/jira/browse/SOLR-13898?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16968676#comment-16968676
 ] 

Ben Manes commented on SOLR-13898:
----------------------------------

FYI,
{{ConcurrentHashMap#computeIfAbsent}} is pessimistic and locks more 
aggressively than you might expect. In Java 8 it will always lock, even if 
present. In Java 9 it will perform a partial prescreen - if the first entry in 
the hashbin is the desired entry then return, else lock and scan the bucket. 
Caffeine always does a full prescreen, which means a present entry is always 
retrieved lock-free. When 
[talking|http://jsr166-concurrency.10961.n7.nabble.com/Re-ConcurrentHashMap-computeIfAbsent-td11687.html]
 to Doug Lea in Java 8 time-frame, he adopted a pessimistic stance due to 
biased locking and safepoints at 32+ cores favors that approach.

You may want to offer a similar optimization in your non-Caffeine 
implementations to perform a `get(key)` and fallback to {{computeIfAbsent}}. I 
haven't benchmarked at Java 9, but you can see the results in Java 8 were 
[dramatic|https://github.com/ben-manes/caffeine/wiki/Benchmarks#compute].

> Non-atomic use of SolrCache get / put
> -------------------------------------
>
>                 Key: SOLR-13898
>                 URL: https://issues.apache.org/jira/browse/SOLR-13898
>             Project: Solr
>          Issue Type: Bug
>      Security Level: Public(Default Security Level. Issues are Public) 
>    Affects Versions: 8.3
>            Reporter: Andrzej Bialecki
>            Assignee: Andrzej Bialecki
>            Priority: Major
>             Fix For: 8.4
>
>         Attachments: SOLR-13898.patch
>
>
> As pointed out by [~ben.manes] in SOLR-13817 Solr code base in many key 
> places uses a similar pattern of non-atomic get / put calls to SolrCache-s. 
> In multi-threaded environment this leads to cache misses and additional 
> unnecessary computations when competing threads both discover a missing 
> value, non-atomically compute it and update the cache.
> Some of these places are known performance bottlenecks where efficient 
> caching is especially important, such as {{SolrIndexSearcher}}, 
> {{SolrDocumentFetcher}}, {{UninvertedField}} and join queries .
> I propose to add {{SolrCache.computeIfAbsent(key, mappingFunction)}} that 
> will atomically retrieve existing values or compute and update the cache. 
> This will require also changing how the {{SolrCache.get(...)}} is used in 
> many components.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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

Reply via email to