Skip to content

Comments

Improve AssignmentMetadataStore with double-checked locking#2289

Merged
junkaixue merged 1 commit intoapache:masterfrom
qqu0127:double-checked
Dec 15, 2022
Merged

Improve AssignmentMetadataStore with double-checked locking#2289
junkaixue merged 1 commit intoapache:masterfrom
qqu0127:double-checked

Conversation

@qqu0127
Copy link
Contributor

@qqu0127 qqu0127 commented Nov 21, 2022

Issues

  • My PR addresses the following Helix issues and references them in the PR description:
    N.A.

Description

  • Here are some details about my PR, including screenshots of any UI changes:

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

  • The following tests are written for this issue:

CI test passed

  • The following is the result of the "mvn test" command on the appropriate module:
    [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)

  • My PR contains changes that break backward compatibility or previous assumptions for certain methods or API. They include:

(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)

  • In case of new functionality, my PR adds documentation in the following wiki page:

(Link the GitHub wiki you added)

Commits

  • My commits all reference appropriate Apache Helix GitHub issues in their subject lines. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Code Quality

  • My diff has been formatted using helix-style.xml
    (helix-style-intellij.xml if IntelliJ IDE is used)

@qqu0127 qqu0127 requested a review from NealSun96 December 6, 2022 16:38
Copy link
Contributor

@desaikomal desaikomal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@qqu0127
Copy link
Contributor Author

qqu0127 commented Dec 8, 2022

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.

Copy link
Contributor

@desaikomal desaikomal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks Quincy.

@qqu0127
Copy link
Contributor Author

qqu0127 commented Dec 13, 2022

This PR is ready to merge, approved by @desaikomal
Commit message:
Implement double-checked locking in AssignmentMetadataStore for better performance.

@junkaixue
Copy link
Contributor

Could you please elaborate a little bit why the double locking helps improvement the performance?

@qqu0127
Copy link
Contributor Author

qqu0127 commented Dec 13, 2022

Could you please elaborate a little bit why the double locking helps improvement the performance?
@junkaixue
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
(I'll link this to the description as well)

@junkaixue junkaixue merged commit 3ca0620 into apache:master Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants