Improve AssignmentMetadataStore with double-checked locking#2289
Improve AssignmentMetadataStore with double-checked locking#2289junkaixue merged 1 commit intoapache:masterfrom
Conversation
...core/src/main/java/org/apache/helix/controller/rebalancer/waged/AssignmentMetadataStore.java
Show resolved
Hide resolved
desaikomal
left a comment
There was a problem hiding this comment.
If i understood correctly, you reduced the scope of 'synchronized' by making 2 variables 'volatile' and checking against it.
Code changes looks good to me.
@desaikomal Yes, it's double-checked locking. This reduces the overhead of obtaining the lock if the variable has been created. |
|
This PR is ready to merge, approved by @desaikomal |
|
Could you please elaborate a little bit why the double locking helps improvement the performance? |
|
Issues
N.A.
Description
Implement double-checked locking in AssignmentMetadataStore to improve method performance. After the first call to initialize, the subsequent calls to getBaseline and getBestPossibleAssignment don't need to obtain the lock.
Double-checked locking:
This is a common pattern to reduce the overhead of obtaining lock, there is no need to synchronize on the instance if the variable has been created. See https://www.baeldung.com/java-singleton-double-checked-locking and https://stackoverflow.com/questions/17164454/why-double-checked-locking-is-25-faster-in-joshua-bloch-effective-java-example
Tests
CI test passed
[info] ./helix-core/target/surefire-reports/TestSuite.txt: Tests run: 1319, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5,894.718 s - in TestSuite
[info] ./helix-lock/target/surefire-reports/TestSuite.txt: Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 57.5 s - in TestSuite
[info] ./recipes/rsync-replicated-file-system/target/surefire-reports/TestSuite.txt: Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.341 s - in TestSuite
[info] ./recipes/distributed-lock-manager/target/surefire-reports/TestSuite.txt: Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.496 s - in TestSuite
[info] ./recipes/rabbitmq-consumer-group/target/surefire-reports/TestSuite.txt: Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.477 s - in TestSuite
[info] ./recipes/task-execution/target/surefire-reports/TestSuite.txt: Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.485 s - in TestSuite
[info] ./recipes/service-discovery/target/surefire-reports/TestSuite.txt: Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.617 s - in TestSuite
[info] ./metrics-common/target/surefire-reports/TestSuite.txt: Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.304 s - in TestSuite
[info] ./helix-view-aggregator/target/surefire-reports/TestSuite.txt: Tests run: 15, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 102.9 s - in TestSuite
[info] ./helix-rest/target/surefire-reports/TestSuite.txt: Tests run: 209, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 157.102 s - in TestSuite
[info] ./helix-common/target/surefire-reports/TestSuite.txt: Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.287 s - in TestSuite
[info] ./zookeeper-api/target/surefire-reports/TestSuite.txt: Tests run: 67, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 141.655 s - in TestSuite
[info] ./metadata-store-directory-common/target/surefire-reports/TestSuite.txt: Tests run: 31, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.526 s - in TestSuite
Changes that Break Backward Compatibility (Optional)
(Consider including all behavior changes for public methods or API. Also include these changes in merge description so that other developers are aware of these changes. This allows them to make relevant code changes in feature branches accounting for the new method/API behavior.)
Documentation (Optional)
(Link the GitHub wiki you added)
Commits
Code Quality
(helix-style-intellij.xml if IntelliJ IDE is used)