-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[improve][broker] Make MessageRedeliveryController work more efficiently #17804
[improve][broker] Make MessageRedeliveryController work more efficiently #17804
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Nice!
} | ||
} | ||
|
||
public synchronized void removeUpTo(long item1, long item2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: why do we need synchronized
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😁, I copied the method signature from another class
import org.apache.pulsar.common.util.collections.LongPairSet; | ||
import org.roaringbitmap.RoaringBitmap; | ||
|
||
public class BitmapSortedLongPairSet { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can indicate this class is thread-safe by adding a comment or name like Concurrent***
?
Map.Entry<Long, RoaringBitmap> firstEntry = map.firstEntry(); | ||
while (firstEntry != null && firstEntry.getKey() <= item1) { | ||
if (firstEntry.getKey() < item1) { | ||
map.remove(firstEntry.getKey(), firstEntry.getValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to avoid loop traversal by using subMap
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sub map will have the low and upper boundaries. If we change to sub map here e.g. from 3 to 10, you will not able to add 2 or 11 again.
pulsar-broker/src/main/java/org/apache/pulsar/utils/ConcurrentBitmapSortedLongPairSet.java
Show resolved
Hide resolved
…tly (apache#17804) (cherry picked from commit c60f895) (cherry picked from commit 19eb842)
…tly (apache#17804) (cherry picked from commit c60f895)
…request !71) [improve][broker] Make MessageRedeliveryController work more efficiently (apache#17804)
Fixes: #15445
Motivation
The implementation of MessageRedeliveryController is inefficient
The issue usually happens if you have a large number of backlogs with the Key_Shared subscription. The publish latency will go high due to the IO thread and
BookKeeperClientWorker
thread with high high CPU usageA related fix #15354, but the fix can't fix the case that the
MessageRedeliveryController
have many redelivery messagesThis PR can make the
MessageRedeliveryController
work more efficiently by introducing a new Ordered Map and Bitmap based LongPair Ordered SetAnd the issue can be reproduced by standalone and pulsar-perf
bin/pulsar-perf produce test -r 1000 -bm 1 -mk random
bin/pulsar-perf consume -st Key_Shared -r 100 -n 50 test
With this PR, the situation will not happen
Modifications
Verifying this change
New test added BitmapSortedLongPairSetTest
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
doc-required
(Your PR needs to update docs, and you will update later)
doc-not-needed
(Please explain why)
doc
(Your PR contains doc changes)
doc-complete
(Docs have been already added)
Matching PR in forked repository
PR in forked repository: codelipenghui#14