[
https://issues.apache.org/jira/browse/HBASE-16648?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15506690#comment-15506690
]
Duo Zhang commented on HBASE-16648:
-----------------------------------
Rewrite the JMH test and run it again.
{noformat}
./bin/run.sh -f 1 -t 1 CIATest.*
Benchmark Mode Cnt Score Error Units
CIATest.testComputeIfAbsent thrpt 20 1306.103 ± 15.932 ops/s
CIATest.testComputeIfAbsentContentional thrpt 20 2055.595 ± 96.389 ops/s
CIATest.testPutIfAbsent thrpt 20 2141.346 ± 34.509 ops/s
CIATest.testPutIfAbsentContentional thrpt 20 4150.031 ± 38.967 ops/s
./bin/run.sh -f 1 -t 10 CIATest.*
Benchmark Mode Cnt Score Error Units
CIATest.testComputeIfAbsent thrpt 20 5521.837 ± 35.690 ops/s
CIATest.testComputeIfAbsentContentional thrpt 20 3425.171 ± 214.103 ops/s
CIATest.testPutIfAbsent thrpt 20 17425.723 ± 284.651 ops/s
CIATest.testPutIfAbsentContentional thrpt 20 37961.718 ± 4233.910 ops/s
{noformat}
The contention could make computeIfAbsent run much slower. And putIfAbsent is
always much faster than computeIfAbsent. Especially when multi-threaded.
I think we should reconsider the implementations here. Maybe we could add a
computeIfAbsent method in CollectionUtils which uses the default implementation
in ConcurrentMap. FWIW, it could make the code cleaner.
Thanks.
> [JDK8] Use computeIfAbsent instead of get and putIfAbsent
> ---------------------------------------------------------
>
> Key: HBASE-16648
> URL: https://issues.apache.org/jira/browse/HBASE-16648
> Project: HBase
> Issue Type: Sub-task
> Components: Performance
> Affects Versions: 2.0.0
> Reporter: Duo Zhang
> Assignee: Duo Zhang
> Fix For: 2.0.0
>
> Attachments: HBASE-16648-v1.patch, HBASE-16648-v2.patch,
> HBASE-16648.patch
>
>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)