You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "codelipenghui (via GitHub)" <gi...@apache.org> on 2023/06/26 04:20:41 UTC
[GitHub] [pulsar] codelipenghui opened a new pull request, #20647: [fix][broker] Fix the publish latency spike from the contention of MessageDeduplication
codelipenghui opened a new pull request, #20647:
URL: https://github.com/apache/pulsar/pull/20647
### Motivation
The issue has happened for a topic that has many producers. When many producers connect/disconnect to the topic, the P99 publish latency of the broker will go up to hundreds of ms, which is unacceptable for a messaging system.
Each producer add/remove operation will go to MessageDeduplication to update a map for inactive producers regardless of whether message deduplication is enabled or disabled. My first intuitive impression is it shouldn't go to MessageDeduplication if the message deduplication is disabled. But users can enable the message deduplication for an active topic. It might be the reason, but I'm not 100% sure about it. @merlimat Do you happen to have more context about it? And we might also need to look for a solution to avoid any operations to the MessageDeduplication if the message deduplication is disabled.
This PR provides a fix without introducing behavior changes, so we will be more confident to cherry-pick to release branches.
<img width="1900" alt="image" src="https://github.com/apache/pulsar/assets/12592133/87c22ac2-2af9-4190-a1f2-1872477dd0c4">
[broker_lock_0621_1.html.txt](https://github.com/apache/pulsar/files/11863016/broker_lock_0621_1.html.txt)
### Modifications
Use ConcurrentOpenHashMap instead of synchronized HashMap to reduce the contention between IO threads.
### Verifying this change
The existing tests can cover the new changes.
### 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 -->
- [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->
--
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 #20647: [fix][broker] Fix the publish latency spike from the contention of MessageDeduplication
Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao commented on code in PR #20647:
URL: https://github.com/apache/pulsar/pull/20647#discussion_r1241755375
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/MessageDeduplication.java:
##########
@@ -455,23 +455,17 @@ public synchronized void producerRemoved(String producerName) {
public synchronized void purgeInactiveProducers() {
long minimumActiveTimestamp = System.currentTimeMillis() - TimeUnit.MINUTES
.toMillis(pulsar.getConfiguration().getBrokerDeduplicationProducerInactivityTimeoutMinutes());
-
- Iterator<java.util.Map.Entry<String, Long>> mapIterator = inactiveProducers.entrySet().iterator();
- boolean hasInactive = false;
- while (mapIterator.hasNext()) {
- java.util.Map.Entry<String, Long> entry = mapIterator.next();
- String producerName = entry.getKey();
- long lastActiveTimestamp = entry.getValue();
-
+ final AtomicBoolean hasInactive = new AtomicBoolean(false);
+ inactiveProducers.forEach((producerName, lastActiveTimestamp) -> {
if (lastActiveTimestamp < minimumActiveTimestamp) {
log.info("[{}] Purging dedup information for producer {}", topic.getName(), producerName);
- mapIterator.remove();
+ inactiveProducers.remove(producerName);
Review Comment:
`ConcurrentModificationException`?
--
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] eolivelli commented on a diff in pull request #20647: [fix][broker] Fix the publish latency spike from the contention of MessageDeduplication
Posted by "eolivelli (via GitHub)" <gi...@apache.org>.
eolivelli commented on code in PR #20647:
URL: https://github.com/apache/pulsar/pull/20647#discussion_r1241767592
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/MessageDeduplication.java:
##########
@@ -455,23 +455,17 @@ public synchronized void producerRemoved(String producerName) {
public synchronized void purgeInactiveProducers() {
Review Comment:
do we need to keep this 'synchronized' ?
--
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 pull request #20647: [fix][broker] Fix the publish latency spike from the contention of MessageDeduplication
Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao commented on PR #20647:
URL: https://github.com/apache/pulsar/pull/20647#issuecomment-1606892478
@codelipenghui
https://github.com/apache/pulsar/actions/runs/5373765736/jobs/9748615177?pr=20647 Please help check this failed job.
--
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] lhotari commented on pull request #20647: [fix][broker] Fix the publish latency spike from the contention of MessageDeduplication
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on PR #20647:
URL: https://github.com/apache/pulsar/pull/20647#issuecomment-1607289470
> @codelipenghui
>
> https://github.com/apache/pulsar/actions/runs/5373765736/jobs/9748615177?pr=20647 Please help check this failed job.
@codelipenghui exception is
```
Error: Tests run: 4, Failures: 1, Errors: 0, Skipped: 3, Time elapsed: 0.665 s <<< FAILURE! - in org.apache.pulsar.broker.service.persistent.MessageDuplicationTest
Error: org.apache.pulsar.broker.service.persistent.MessageDuplicationTest.testInactiveProducerRemove Time elapsed: 0.056 s <<< FAILURE!
java.lang.ClassCastException: class org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap cannot be cast to class java.util.Map (org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap is in unnamed module of loader 'app'; java.util.Map is in module java.base of loader 'bootstrap')
at org.apache.pulsar.broker.service.persistent.MessageDuplicationTest.testInactiveProducerRemove(MessageDuplicationTest.java:177)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
at org.testng.internal.invokers.InvokeMethodRunnable.runOne(InvokeMethodRunnable.java:47)
at org.testng.internal.invokers.InvokeMethodRunnable.call(InvokeMethodRunnable.java:76)
at org.testng.internal.invokers.InvokeMethodRunnable.call(InvokeMethodRunnable.java:11)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
```
--
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] codelipenghui commented on pull request #20647: [fix][broker] Fix the publish latency spike from the contention of MessageDeduplication
Posted by "codelipenghui (via GitHub)" <gi...@apache.org>.
codelipenghui commented on PR #20647:
URL: https://github.com/apache/pulsar/pull/20647#issuecomment-1607257960
After doing a [benchmark test](https://github.com/apache/pulsar/pull/20648/files)
We should use ConcurrentHashMap here, it performed super better than ConcurrentOpenHashMap and synchronized HashMap for put/remove operations.
```
CLHM_CON::Thread-3::put: 422ms
CLHM_CON::Thread-5::put: 422ms
CLHM_CON::Thread-4::put: 422ms
CLHM_CON::Thread-0::put: 423ms
CLHM_CON::Thread-2::put: 422ms
CLHM_CON::Thread-1::put: 423ms
CLHM_CON::Thread-0::get: 786ms
CLHM_CON::Thread-1::get: 805ms
CLHM_CON::Thread-4::get: 839ms
CLHM_CON::Thread-5::get: 840ms
CLHM_CON::Thread-3::get: 854ms
CLHM_CON::Thread-2::get: 855ms
CLHM_CON::Thread-0::remove: 112ms
CLHM_CON::Thread-1::remove: 123ms
CLHM_CON::Thread-4::remove: 97ms
CLHM_CON::Thread-5::remove: 97ms
CLHM_CON::Thread-2::remove: 84ms
CLHM_CON::Thread-3::remove: 85ms
CLHM_CON: 1367 ms
CHM_CON::Thread-7::put: 33ms
CHM_CON::Thread-6::put: 35ms
CHM_CON::Thread-9::put: 37ms
CHM_CON::Thread-8::put: 38ms
CHM_CON::Thread-11::put: 38ms
CHM_CON::Thread-10::put: 39ms
CHM_CON::Thread-9::get: 630ms
CHM_CON::Thread-10::get: 629ms
CHM_CON::Thread-7::get: 635ms
CHM_CON::Thread-11::get: 630ms
CHM_CON::Thread-8::get: 631ms
CHM_CON::Thread-6::get: 635ms
CHM_CON::Thread-10::remove: 11ms
CHM_CON::Thread-6::remove: 9ms
CHM_CON::Thread-7::remove: 11ms
CHM_CON::Thread-8::remove: 10ms
CHM_CON::Thread-11::remove: 11ms
CHM_CON::Thread-9::remove: 12ms
CHM_CON: 680 ms
HM_CON::Thread-16::put: 643ms
HM_CON::Thread-15::put: 664ms
HM_CON::Thread-14::put: 670ms
HM_CON::Thread-13::put: 674ms
HM_CON::Thread-17::put: 687ms
HM_CON::Thread-12::put: 715ms
HM_CON::Thread-16::get: 61876ms
HM_CON::Thread-15::get: 62214ms
HM_CON::Thread-13::get: 62312ms
HM_CON::Thread-17::get: 62309ms
HM_CON::Thread-14::get: 62450ms
HM_CON::Thread-16::remove: 638ms
HM_CON::Thread-15::remove: 555ms
HM_CON::Thread-13::remove: 521ms
HM_CON::Thread-17::remove: 522ms
HM_CON::Thread-14::remove: 411ms
HM_CON::Thread-12::get: 62816ms
HM_CON::Thread-12::remove: 8ms
HM_CON: 63538 ms
```
--
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 pull request #20647: [fix][broker] Fix the publish latency spike from the contention of MessageDeduplication
Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao commented on PR #20647:
URL: https://github.com/apache/pulsar/pull/20647#issuecomment-1607298235
@codelipenghui
You have to avoid using `remove` in `for-each` If you chose `ConcurrentHashMap` . because there is a `.ConcurrentModificationException`
--
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] codelipenghui commented on pull request #20647: [fix][broker] Fix the publish latency spike from the contention of MessageDeduplication
Posted by "codelipenghui (via GitHub)" <gi...@apache.org>.
codelipenghui commented on PR #20647:
URL: https://github.com/apache/pulsar/pull/20647#issuecomment-1608593676
> You have to avoid using remove in for-each If you chose ConcurrentHashMap . because there is a .ConcurrentModificationException
@mattisonchao I need to use iterator if the ConcurrentHashMap is the final decision.
--
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] codelipenghui commented on pull request #20647: [fix][broker] Fix the publish latency spike from the contention of MessageDeduplication
Posted by "codelipenghui (via GitHub)" <gi...@apache.org>.
codelipenghui commented on PR #20647:
URL: https://github.com/apache/pulsar/pull/20647#issuecomment-1606571186
/pulsarbot run-failure-checks
--
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] codelipenghui commented on a diff in pull request #20647: [fix][broker] Fix the publish latency spike from the contention of MessageDeduplication
Posted by "codelipenghui (via GitHub)" <gi...@apache.org>.
codelipenghui commented on code in PR #20647:
URL: https://github.com/apache/pulsar/pull/20647#discussion_r1241867649
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/MessageDeduplication.java:
##########
@@ -455,23 +455,17 @@ public synchronized void producerRemoved(String producerName) {
public synchronized void purgeInactiveProducers() {
Review Comment:
I think we don't need it, and I also want to remove it in this PR initially. But considering it is not related to the publish latency spike issue, maybe we'd better just keep this PR only for the publish latency spike issue. And I can create the following PR to remove this `synchronized`, but no need to cherry-pick to release branches.
--
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] codecov-commenter commented on pull request #20647: [fix][broker] Fix the publish latency spike from the contention of MessageDeduplication
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #20647:
URL: https://github.com/apache/pulsar/pull/20647#issuecomment-1612354025
## [Codecov](https://app.codecov.io/gh/apache/pulsar/pull/20647?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
> Merging [#20647](https://app.codecov.io/gh/apache/pulsar/pull/20647?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (b0cebfd) into [master](https://app.codecov.io/gh/apache/pulsar/commit/2b01f83ea4f3ab7b22f4ea2b0290cc183e79bbb8?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (2b01f83) will **increase** coverage by `39.54%`.
> The diff coverage is `100.00%`.
[](https://app.codecov.io/gh/apache/pulsar/pull/20647?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #20647 +/- ##
=============================================
+ Coverage 33.58% 73.12% +39.54%
- Complexity 12127 32016 +19889
=============================================
Files 1613 1867 +254
Lines 126241 138683 +12442
Branches 13770 15240 +1470
=============================================
+ Hits 42396 101410 +59014
+ Misses 78331 29249 -49082
- Partials 5514 8024 +2510
```
| Flag | Coverage Δ | |
|---|---|---|
| inttests | `24.18% <50.00%> (-0.01%)` | :arrow_down: |
| systests | `25.02% <50.00%> (?)` | |
| unittests | `72.36% <100.00%> (+40.32%)` | :arrow_up: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Impacted Files](https://app.codecov.io/gh/apache/pulsar/pull/20647?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...roker/service/persistent/MessageDeduplication.java](https://app.codecov.io/gh/apache/pulsar/pull/20647?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9zZXJ2aWNlL3BlcnNpc3RlbnQvTWVzc2FnZURlZHVwbGljYXRpb24uamF2YQ==) | `82.53% <100.00%> (+42.35%)` | :arrow_up: |
... and [1520 files with indirect coverage changes](https://app.codecov.io/gh/apache/pulsar/pull/20647/indirect-changes?src=pr&el=tree-more&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@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] Technoboy- merged pull request #20647: [fix][broker] Fix the publish latency spike from the contention of MessageDeduplication
Posted by "Technoboy- (via GitHub)" <gi...@apache.org>.
Technoboy- merged PR #20647:
URL: https://github.com/apache/pulsar/pull/20647
--
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