-
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] replace HashMap with inner implementation ConcurrentLongLongPairHashMap in Negative Ack Tracker. #23582
Conversation
to reduce memory consumption.
@thetumbled Please add the following content to your PR description and select a checkbox:
|
pulsar-client/src/main/java/org/apache/pulsar/client/impl/NegativeAcksTracker.java
Show resolved
Hide resolved
btw. In Fastutil, there's also Obj2LongMap interface which would be applicable in this case when the value is a |
No, there is no shrink logic triggerd in the test code, as i only add new item into the map, without any deletion. Shrinking logic is triggered by item deletion. |
…ntLongLongPairHashMap in Negative Ack Tracker. (apache#23582) (cherry picked from commit 9d65a85) (cherry picked from commit 431c232)
…ntLongLongPairHashMap in Negative Ack Tracker. (apache#23582) (cherry picked from commit 9d65a85) (cherry picked from commit 431c232)
Motivation
Negative ack feature need to retain the message id and timestamp info in the memory of the consumer client side, leading to great memory consumption.
This PR aim to replace the
HashMap
with the inner map implementationConcurrentLongLongPairHashMap
to reduce the memory consumption. ThoughHashMap
is faster than the inner map implementationConcurrentLongLongPairHashMap
in some cases, but the most important issue in this case is memory consumption instead of the speed.Some test data list as follows:
experiment 1
HashMap:178Mb
ConcurrentLongLongPairHashMap:64Mb
HashMap:566Mb
ConcurrentLongLongPairHashMap:256Mb
HashMap:1132MB
Approximately each entry consume 1132MB/10000000=118byte.
ConcurrentLongLongPairHashMap:512MB
Approximately each entry consume 512MB/10000000=53byte.
With this improvement, we can reduce 50+% of the memory consumption!
experiment 2
Test three candidate data structures:
org.apache.pulsar.common.util.collections.ConcurrentLongPairSet.LongPair
it.unimi.dsi.fastutil.longs.LongLongPair
Test code:
The results list as follows:
Conclusion:
HashMap<LongPair, Long> 91MB
HashMap<LongLongPair, Long> 114MB
ConcurrentLongLongPairHashMap 64MB
HashMap<LongPair, Long> 451MB
HashMap<LongLongPair, Long> 566MB
ConcurrentLongLongPairHashMap 256MB
It shows that the
ConcurrentLongLongPairHashMap
is still the best option to store enormous amount of entries.Modifications
Replace
HashMap
withConcurrentLongLongPairHashMap
in Negative Ack Tracker.Verifying this change
(Please pick either of the following options)
This change is already covered by existing tests, such as (please describe tests).
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: thetumbled#63