You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "mxsm (via GitHub)" <gi...@apache.org> on 2023/05/21 15:38:00 UTC
[GitHub] [rocketmq] mxsm opened a new pull request, #6783: [ISSUE #6782]Optimize and streamline ConsumeQueueStore#doFindOrCreateConsumeQueue code
mxsm opened a new pull request, #6783:
URL: https://github.com/apache/rocketmq/pull/6783
<!-- Please make sure the target branch is right. In most case, the target branch should be `develop`. -->
### Which Issue(s) This PR Fixes
<!-- Please ensure that the related issue has already been created, and [link this pull request to that issue using keywords](<https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword>) to ensure automatic closure. -->
Fixes #6782
### Brief Description
<!-- Write a brief description for your pull request to help the maintainer understand the reasons behind your changes. -->
- Optimize and streamline ConsumeQueueStore#doFindOrCreateConsumeQueue code
### How Did You Test This Change?
<!-- In order to ensure the code quality of Apache RocketMQ, we expect every pull request to have undergone thorough testing. -->
--
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@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [rocketmq] mxsm commented on a diff in pull request #6783: [ISSUE #6782]Optimize and streamline ConsumeQueueStore#doFindOrCreateConsumeQueue code
Posted by "mxsm (via GitHub)" <gi...@apache.org>.
mxsm commented on code in PR #6783:
URL: https://github.com/apache/rocketmq/pull/6783#discussion_r1247381129
##########
store/src/main/java/org/apache/rocketmq/store/queue/ConsumeQueueStore.java:
##########
@@ -314,50 +315,42 @@ public ConsumeQueueInterface findOrCreateConsumeQueue(String topic, int queueId)
return doFindOrCreateConsumeQueue(topic, queueId);
}
+ /**
+ * Finds or creates a ConsumeQueueInterface for the given topic and queue ID.
+ *
+ * @param topic The topic for which the ConsumeQueueInterface.
+ * @param queueId The ID of the queue for which the ConsumeQueueInterface.
+ * @return The found or newly created ConsumeQueueInterface.
+ */
private ConsumeQueueInterface doFindOrCreateConsumeQueue(String topic, int queueId) {
- ConcurrentMap<Integer, ConsumeQueueInterface> map = consumeQueueTable.get(topic);
- if (null == map) {
- ConcurrentMap<Integer, ConsumeQueueInterface> newMap = new ConcurrentHashMap<>(128);
- ConcurrentMap<Integer, ConsumeQueueInterface> oldMap = consumeQueueTable.putIfAbsent(topic, newMap);
- if (oldMap != null) {
- map = oldMap;
- } else {
- map = newMap;
- }
- }
+ ConcurrentMap<Integer, ConsumeQueueInterface> map = ConcurrentHashMapUtils.computeIfAbsent(consumeQueueTable, topic, k -> new ConcurrentHashMap<>(128));
Review Comment:
> jdk8 的 computeIfAbsent 性能有问题
ConcurrentHashMapUtils utility class addresses performance issues, JMH test results #5008. However, this utility class does not solve the problem mentioned in https://bugs.openjdk.org/browse/JDK-8062841. I noticed that there is a related PR #6883 already.
--
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@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [rocketmq] codecov-commenter commented on pull request #6783: [ISSUE #6782]Optimize and streamline ConsumeQueueStore#doFindOrCreateConsumeQueue code
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #6783:
URL: https://github.com/apache/rocketmq/pull/6783#issuecomment-1556213575
## [Codecov](https://app.codecov.io/gh/apache/rocketmq/pull/6783?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
> Merging [#6783](https://app.codecov.io/gh/apache/rocketmq/pull/6783?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (edd5e4b) into [develop](https://app.codecov.io/gh/apache/rocketmq/commit/bd7db7ec62164882ce6db101bacd038308648e02?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (bd7db7e) will **decrease** coverage by `0.07%`.
> The diff coverage is `100.00%`.
```diff
@@ Coverage Diff @@
## develop #6783 +/- ##
=============================================
- Coverage 42.92% 42.86% -0.07%
+ Complexity 8985 8971 -14
=============================================
Files 1104 1104
Lines 78376 78369 -7
Branches 10203 10201 -2
=============================================
- Hits 33645 33590 -55
- Misses 40512 40562 +50
+ Partials 4219 4217 -2
```
| [Impacted Files](https://app.codecov.io/gh/apache/rocketmq/pull/6783?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...apache/rocketmq/store/queue/ConsumeQueueStore.java](https://app.codecov.io/gh/apache/rocketmq/pull/6783?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3RvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3JvY2tldG1xL3N0b3JlL3F1ZXVlL0NvbnN1bWVRdWV1ZVN0b3JlLmphdmE=) | `47.01% <100.00%> (-0.63%)` | :arrow_down: |
... and [14 files with indirect coverage changes](https://app.codecov.io/gh/apache/rocketmq/pull/6783/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
--
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@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [rocketmq] lizhimins commented on a diff in pull request #6783: [ISSUE #6782]Optimize and streamline ConsumeQueueStore#doFindOrCreateConsumeQueue code
Posted by "lizhimins (via GitHub)" <gi...@apache.org>.
lizhimins commented on code in PR #6783:
URL: https://github.com/apache/rocketmq/pull/6783#discussion_r1247358914
##########
store/src/main/java/org/apache/rocketmq/store/queue/ConsumeQueueStore.java:
##########
@@ -314,50 +315,42 @@ public ConsumeQueueInterface findOrCreateConsumeQueue(String topic, int queueId)
return doFindOrCreateConsumeQueue(topic, queueId);
}
+ /**
+ * Finds or creates a ConsumeQueueInterface for the given topic and queue ID.
+ *
+ * @param topic The topic for which the ConsumeQueueInterface.
+ * @param queueId The ID of the queue for which the ConsumeQueueInterface.
+ * @return The found or newly created ConsumeQueueInterface.
+ */
private ConsumeQueueInterface doFindOrCreateConsumeQueue(String topic, int queueId) {
- ConcurrentMap<Integer, ConsumeQueueInterface> map = consumeQueueTable.get(topic);
- if (null == map) {
- ConcurrentMap<Integer, ConsumeQueueInterface> newMap = new ConcurrentHashMap<>(128);
- ConcurrentMap<Integer, ConsumeQueueInterface> oldMap = consumeQueueTable.putIfAbsent(topic, newMap);
- if (oldMap != null) {
- map = oldMap;
- } else {
- map = newMap;
- }
- }
+ ConcurrentMap<Integer, ConsumeQueueInterface> map = ConcurrentHashMapUtils.computeIfAbsent(consumeQueueTable, topic, k -> new ConcurrentHashMap<>(128));
Review Comment:
jdk8 的 computeIfAbsent 性能有问题
--
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@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org