You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "lifepuzzlefun (via GitHub)" <gi...@apache.org> on 2023/06/06 05:18:21 UTC
[GitHub] [pulsar] lifepuzzlefun opened a new pull request, #20506: [imporve] [broker] Replace `AtomicLong` with `LongAdder` in `RangeEntryCacheManagerImpl`
lifepuzzlefun opened a new pull request, #20506:
URL: https://github.com/apache/pulsar/pull/20506
### Motivation
common optimization use LongAdder which have less cost when thread contention is high.
### Modifications
Replace `AtomicLong` with `LongAdder`
### Verifying this change
This change is already covered by existing tests, such as *(please describe tests)*.
### Does this pull request potentially affect one of the following parts:
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
*If the box was checked, please highlight the changes*
- [ ] Dependencies (add or upgrade a dependency)
- [ ] The public API
- [ ] The schema
- [ ] The default values of configurations
- [ ] The threading model
- [ ] The binary protocol
- [ ] The REST endpoints
- [ ] The admin CLI options
- [ ] The metrics
- [ ] Anything that affects deployment
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc` <!-- Your PR contains doc changes. -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
- [ ] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->
### Matching PR in forked repository
PR in forked repository: <!-- ENTER URL HERE -->
<!--
After opening this PR, the build in apache/pulsar will fail and instructions will
be provided for opening a PR in the PR author's forked repository.
apache/pulsar pull requests should be first tested in your own fork since the
apache/pulsar CI based on GitHub Actions has constrained resources and quota.
GitHub Actions provides separate quota for pull requests that are executed in
a forked repository.
The tests will be run in the forked repository until all PR review comments have
been handled, the tests pass and the PR is approved by a reviewer.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] lifepuzzlefun closed pull request #20506: [improve] [broker] Replace `AtomicLong` with `LongAdder` in `RangeEntryCacheManagerImpl`
Posted by "lifepuzzlefun (via GitHub)" <gi...@apache.org>.
lifepuzzlefun closed pull request #20506: [improve] [broker] Replace `AtomicLong` with `LongAdder` in `RangeEntryCacheManagerImpl`
URL: https://github.com/apache/pulsar/pull/20506
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] mattisonchao commented on a diff in pull request #20506: [improve] [broker] Replace `AtomicLong` with `LongAdder` in `RangeEntryCacheManagerImpl`
Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao commented on code in PR #20506:
URL: https://github.com/apache/pulsar/pull/20506#discussion_r1220639752
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/RangeEntryCacheManagerImpl.java:
##########
@@ -106,12 +106,12 @@ public void removeEntryCache(String name) {
entryCache.clear();
if (log.isDebugEnabled()) {
- log.debug("Removed cache for {} - Size: {} -- Current Size: {}", name, size / MB, currentSize.get() / MB);
+ log.debug("Removed cache for {} - Size: {} -- Current Size: {}", name, size / MB, currentSize.sum() / MB);
}
}
boolean hasSpaceInCache() {
- long currentSize = this.currentSize.get();
+ long currentSize = this.currentSize.sum();
Review Comment:
+1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] lifepuzzlefun commented on pull request #20506: [improve] [broker] Replace `AtomicLong` with `LongAdder` in `RangeEntryCacheManagerImpl`
Posted by "lifepuzzlefun (via GitHub)" <gi...@apache.org>.
lifepuzzlefun commented on PR #20506:
URL: https://github.com/apache/pulsar/pull/20506#issuecomment-1587476134
thanks for the review. after write a jmh test it seems the performance not that good if LongAdder `add` and `get` have 1:1 access call.
the jmh test here. https://gist.github.com/lifepuzzlefun/03f9333a8f33c32c66e63ea4ba40f7fb
the result
Benchmark Mode Cnt Score Error Units
IteratorTest.longAdder thrpt 25 40.073 ± 0.443 ops/us
IteratorTest.longCounter thrpt 25 41.377 ± 1.111 ops/us
I'll try to be more careful next time : - )
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] michaeljmarshall commented on a diff in pull request #20506: [improve] [broker] Replace `AtomicLong` with `LongAdder` in `RangeEntryCacheManagerImpl`
Posted by "michaeljmarshall (via GitHub)" <gi...@apache.org>.
michaeljmarshall commented on code in PR #20506:
URL: https://github.com/apache/pulsar/pull/20506#discussion_r1220037148
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/RangeEntryCacheManagerImpl.java:
##########
@@ -106,12 +106,12 @@ public void removeEntryCache(String name) {
entryCache.clear();
if (log.isDebugEnabled()) {
- log.debug("Removed cache for {} - Size: {} -- Current Size: {}", name, size / MB, currentSize.get() / MB);
+ log.debug("Removed cache for {} - Size: {} -- Current Size: {}", name, size / MB, currentSize.sum() / MB);
}
}
boolean hasSpaceInCache() {
- long currentSize = this.currentSize.get();
+ long currentSize = this.currentSize.sum();
Review Comment:
Yes, I was wondering the same thing @merlimat. Many of the calls are from the managed ledger thread, so there might not actually be that much contention. It might help to provide more evidence that this is an optimization.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] merlimat commented on a diff in pull request #20506: [improve] [broker] Replace `AtomicLong` with `LongAdder` in `RangeEntryCacheManagerImpl`
Posted by "merlimat (via GitHub)" <gi...@apache.org>.
merlimat commented on code in PR #20506:
URL: https://github.com/apache/pulsar/pull/20506#discussion_r1220031923
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/RangeEntryCacheManagerImpl.java:
##########
@@ -106,12 +106,12 @@ public void removeEntryCache(String name) {
entryCache.clear();
if (log.isDebugEnabled()) {
- log.debug("Removed cache for {} - Size: {} -- Current Size: {}", name, size / MB, currentSize.get() / MB);
+ log.debug("Removed cache for {} - Size: {} -- Current Size: {}", name, size / MB, currentSize.sum() / MB);
}
}
boolean hasSpaceInCache() {
- long currentSize = this.currentSize.get();
+ long currentSize = this.currentSize.sum();
Review Comment:
This operation will become more expensive. If we're checking this everything, it might not be good to do it with `LongAdder`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] mattisonchao commented on a diff in pull request #20506: [improve] [broker] Replace `AtomicLong` with `LongAdder` in `RangeEntryCacheManagerImpl`
Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao commented on code in PR #20506:
URL: https://github.com/apache/pulsar/pull/20506#discussion_r1220639752
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/RangeEntryCacheManagerImpl.java:
##########
@@ -106,12 +106,12 @@ public void removeEntryCache(String name) {
entryCache.clear();
if (log.isDebugEnabled()) {
- log.debug("Removed cache for {} - Size: {} -- Current Size: {}", name, size / MB, currentSize.get() / MB);
+ log.debug("Removed cache for {} - Size: {} -- Current Size: {}", name, size / MB, currentSize.sum() / MB);
}
}
boolean hasSpaceInCache() {
- long currentSize = this.currentSize.get();
+ long currentSize = this.currentSize.sum();
Review Comment:
+1, could you provide something to prove there has some concurrent issue and that your changes can improve the performance?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org